# include <iostream>
using namespace std;

char br[1001][1001];
short w[10000];

int make(int a,int b)
{
    int n=a*b;
    //cout<<n<<endl;
    int ans=0;

    int u=1,i=1;

    if(n<10)
    {
        int d=n%10;
        if(d==0) d=9;
        else d--;
        ans=ans+u*d;

        return ans;
    }

    if(n<100)
    {
        int d=n%10;
        if(d==0) d=9;
        else d--;

        ans=ans+u*d;
        u=u*10;
        n=n/10;

        d=n%10;
        if(d==0) d=9;
        else d--;

        ans=ans+u*d;
        u=u*10;
        n=n/10;

        return ans;
    }

    for(int i=1;i<=3;i++)
    {
        int d=n%10;
        if(d==0) d=9;
        else d--;

        ans=ans+u*d;
        u=u*10;
        n=n/10;
    }

    return ans;
}

int main()
{
    int n,a,b;
    cin>>n>>a>>b;

    if(n==1)
    {
        cout<<a<<endl;
        return 0;
    }

    if(n==2)
    {
        cout<<b<<endl;
        return 0;
    }

    int k=3;
    w[1]=a;w[2]=b;br[a][b]++;

    while(k<=n and br[a][b]<2)
    {
        int c=make(a,b);
        a=b;b=c;
        w[k]=b;
        br[a][b]++;
        k++;
        //cout<<c<<" ";
    }

    if(k-1==n) {cout<<b<<endl;return 0;}

    int l;
    for(int i=k-2;i>=2;i--)
    {
        if(w[i]==b and w[i-1]==a) {l=i-2;break;}
    }

    //cout<<k<<endl<<" "<<l<<endl;

    k=k-l-3;
    n=n-l;

   // cout<<endl<<k<<endl;


    if(n%k==0) cout<<w[l+1]<<endl;
    else cout<<w[n%k+l]<<endl;
    return 0;
}
