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

//ll loop[50000001];

ll transform_num(ll a) {
    ll ans = 0;
    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;
}

int main () {
    ll n, a, b, x, y;
    cin >> n >> a >> b;
    y = a;
//    loop[0] = a;
    x = b;
    for (ll i = 1; i < n; i++) {
//        if (i < 50000000) {
//            loop[i] = x;
//            if ()
//        }
        ll t = y;
        y = x;
        x = transform_num(x * t);
    }
    cout << y;
}
