#include <bits/stdc++.h>
#define ll long long

using namespace std;

ll res(ll p)
{
    ll dig[10] = {0}, idx = 0;

    while (p)
    {
        dig[idx] = p % 10;
        idx++;
        p /= 10;
    }

    bool f[10] = {0};

    for (ll i = idx; i >= 0; i--)
    {
        if (dig[i] > 0)
        {
            dig[i]--;
            f[i] = 1;
        }
    }

    for (ll i = idx; i >= 0; i--)
    {
        if (!f[i])
        {
            if (dig[i] == 0)
            {
                dig[i] = 9;
            }
        }
    }

    ll num = 0;

    for (ll i = idx; i >= 0; i--)
    {
        num *= 10;
        num += dig[i];
    }

    return num % 1000;
}

int main()
{
    ll N, a, b, z;

    cin >> N >> a >> b;

    for (ll i = 1; i <= N - 2; i++)
    {
        z = res(a * b);
        a = b;
        b = z;
    }

    cout << z << endl;

    return 0;
}
