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

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;
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n, a, b, x, y, i;
    cin >> n >> a >> b;
    y = a;
    x = b;
    for (i = 1; i < n; i++) {
        ll t = y;
        y = x;
        x = transform_num(x * t);
    }

    cout << y;
}
