#include <iostream>
#define endl '\n'
using namespace std;

bool flag;

long long funct(long long n)
{
    long long a = n / 100, b = (n / 10) % 10, c = n % 10;

    if (!flag)
    {
        if (a != 0) n = n - 100;
        else  n = n + 900;
    }

    if (b != 0) n = n - 10;
    else n = n + 90;

    if (c != 0) n--;
    else n = n + 9;

    return n;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    long long n, a, b;
    cin >> n >> a >> b;
    if (n == 1)
    {
        cout << a << endl;
        return 0;
    }
    for (long long i = 3; i <= n; i++)
    {
        flag = false;
        long long r = a * b;
        if (r >= 1000 && r / 100 % 10 == 0)
        {
            r = r + 900;
            flag = true;
        }
        r = r % 1000;
        a = b;
        if (r >= 100)
            b = funct(r);
        else
        {
            if (r < 10)
            {
                if (r == 0) r = 9;
                else r--;
            }
            else
            {
                if (r < 100)
                {
                    long long q = r / 10, p = r % 10;
                    if (q == 0) r = r + 90;
                    else r = r - 10;

                    if (p != 0) r--;
                    else r = r + 9;
                }
            }
            b = r;
        }
    }
    cout << b << endl;
}
