#include<iostream>
#include<cmath>
using namespace std;
#define ll long long

ll loop[100000000];
ll transform_num(ll a) {
    ll ans = 0;
    if (a == 0) {
        return 9;
    }
    for (ll i = 0; a > 0; i++) {
        ll temp = (a % 10) - 1;
        if (temp < 0) {
            temp = 9;
        }
        temp *= pow(10, i);
        ans += temp;
        a /= 10;
    }
    return ans % 1000;
}


///1000000 0 0
int main () {
    ll n, a, b, x, y, i;
    bool rem_i = 0;
    cin >> n >> a >> b;
    y = a;
    x = b;
    for (i = 1; i < n; i++) {
        if (i < 100000000) {
            loop[i] = x;
            if (i > 2 && (x == b && y == a)) {
                break;
            }
            if (i > 2 && x == loop[2] && y == loop[1]) {
                rem_i = true;
                break;
            }
//            if (i > 2) {
//                cout << " " << loop[0] << " " << loop[1]<< " " << loop[2] << " " << loop[3] << endl;
//            }
        }
//        cout << i << ": " << x << " " << y << endl;
        ll t = y;
        y = x;
        x = transform_num(x * t);
    }
    if (i != n) {
//        cout << i << " " << n << " " << n % i << endl;
        if (rem_i) {
            i--;
            cout << loop[n % i + 1];
            return 0;
        }
        cout << loop[n % i];
        return 0;
    }

    cout << y;
}
