#include<bits/stdc++.h>
using namespace std;
long long toNum(string& s){
    long long n = 0;
    for(long long i = 0; i < s.size(); i++){
        n*=10;
        n += s[s.size() - i - 1] - '0';
    }
    return n;
}
long long calc(long long a, long long b){
    long long c = (a*b);
    ///cout<<c<<" ";
    long long c2 = c;
    string s = "";
    if(c2 == 0) return 9;
    while(c2 != 0){
        if(c2%10 == 0) s.push_back('9');
        else s.push_back((c2%10 - 1) + '0');
        c2/=10;
    }
    ///cout<<s<<" ";
    long long l = toNum(s);
    ///cout<<l<<" ";
    return l%1000;
}

int main(){
    long long n, a, b, c;
    cin>>n>>a>>b;
    for(long long i = 3; i <= n; i ++){
        ///cout<<a<<" "<<b<<" - ";
        c = b;
        b = calc(a, b);
        a = c;

        ///cout<<a<<" "<<b <<endl;
    }
    cout<<b<<endl;
    return 0;
}
