def ackermann(m_arg=0, n_arg=0):
    """Ackermann function is defined recursively by:

    ackermann(0,n) = n+1
    ackermann(m,0) = ackermann(m-1,1)
    ackermann(m,n) = ackermann(m-1, ackermann(m, n-1)) for n,m > 0
    """

    # Model a function stack with a list, then
    # evaluate innermost ackermann function first.
    acker = [m_arg, n_arg]

    while len(acker) > 1:
        m_arg, n_arg = acker[-2:]
        if m_arg < 1:
            acker[-1] = acker.pop() + 1
        elif n_arg < 1:
            acker[-2] = acker[-2] - 1
            acker[-1] = 1
        else:
            acker[-2] = m_arg - 1
            acker[-1] = m_arg
            acker.append(n_arg-1)

    return acker[0]