#include<bits/stdc++.h>
using namespace std;
int ch[10000];
string s;
long long toNum(){
    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;
    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();
    ///cout<<l<<" ";
    return l%1000;
}

int main(){
    long long n, a, b, c;
    cin>>n>>a>>b;
    ///cout<<a<<" "<<b;
    ch[0] = a;
    ch[1] = b;
    bool haveGroup = false;
    int gS = 0, gE = 0;
    for(long long i = 2; !haveGroup; i ++){
        c = b;
        b = calc(a, b);
        ch[i] = b;
        a = c;
        if(i >= 61){
            if(ch[i - 61] == ch[i - 1] && ch[i - 60] == ch[i]){
                haveGroup = true;
                gS = i - 61;
                gE = gS + 59;
                //cout<<gE<<" "<<i<<endl;
            }
        }
    }
    ///cout<<gS<<" "<<ch[gS]<<" "<<gE<<" "<<ch[gE]<<endl;
    n--;
    if(n <= gE){
        cout<<ch[n]<<endl;
        return 0;
    }
    n -= gS;
    if(n == 0) {
        cout<<ch[gS]<<endl;
        return 0;
    }
    if(n%60 == 0){
        cout<<ch[gE]<<endl;
        return 0;
    }
    cout<<ch[gS + n%60]<<endl;
    return 0;
}
