#include <iostream>
#include <vector>
using namespace std;
int n, a, b;
int genNext(){
    int z=a*b;
    z-=111;
    z%=1000;
    if(z%10==9) z+=10;
    else if(z/10%10==9) z+=100;
    return z;
}
int main(){
    cin>>n>>a>>b;
    int i=2;
    while(i<n){
        if(i%2==0) a=genNext();
        else b=genNext();
        i++;
    }
    if(i%2!=0) cout<<a<<"\n";
    else cout<<b<<"\n";
    return 0;
}
