#include <iostream>
#include <vector>
using namespace std;
int getNext(int pr1, int pr2){
    int z=pr1*pr2, d[3];
    for(int i=0; i<3; i++){
        if(z%10!=0) d[i]=z%10-1;
        else d[i]=9;
        z/=10;
    }
    int ans=d[2]*100+d[1]*10+d[0];
    return ans%1000;
}
int main(){
    int n, a, b;
    cin>>n>>a>>b;
    int i=2;
    bool printA=0;
    while(i<n){
        if(i%2==0) {
            a=getNext(a, b);
            printA=1;
        }
        else {
            b=getNext(b, a);
            printA=0;
        }
        i++;
    }
    if(i%2!=0) cout<<a<<"\n";
    else cout<<b<<"\n";
    return 0;
}
