#include<iostream>
using namespace std;
long long n;
int main()
{
    long long a,b,prob,br1=0,br12,izv=1,br3=0,m,br=2,sum=0;
    cin>>n>>a>>b;
    while(br<=n){
        prob-=sum;

            sum=0;
        if(br>=3){

            a=b;
            b=prob%1000;

        }
       prob=a*b;
       m=prob;
       izv=1;
       while(m>0){



            if(m%10==0){

            sum-=9*izv;
        }else{
        sum+=izv;
        }
        izv*=10;
        m/=10;
       }

        br++;

    }

    cout<<b;
    return 0;
}
