#include<bits/stdc++.h>
using namespace std;
long long a, b, n, curr, ind[1000][1000], ans;
long long solve(long long a){
    long long b=0, c=1;
    if(a==0) return 9;
    while(a!=0){
        if(a%10==0) b+=c*9;
        else b+=c*(a%10-1);
        c*=10;
        a/=10;
    }
    return b%1000;
}
vector<long long> c;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>a>>b;
    /*if(n==1){
        cout<<a;
        return 0;
    }else if(n==2){
        cout<<b;
        return 0;
    }*/
    ind[a][b]=1;
    c.push_back(a);
    c.push_back(b);
    bool ok=false;
    for(int i=3; i<=n; i++){
        curr=a*b;
        curr=solve(curr);
        a=b;
        b=curr;
        c.push_back(curr);
        if(ind[a][b]==0){
            ind[a][b]=i;
        }else{
            ok=true;
            ans=i;
            break;
        }
    }
    if(ok==true){
        long long cu=(n-ind[a][b])%(ans-ind[a][b]);
        cout<<c[cu+ind[a][b]-1];
        return 0;
    }
    cout<<curr;
    return 0;
}
