#include<iostream>
using namespace std;
int main()
{
    int n, a, b, p;
    cin>>n>>a>>b;
    for(int i=2; i<n; i++)
    {
        p=a*b;
        int y=1, t=0;
        while(p>0)
        {
            int z;
            if(p%10==0)z=9;
            else z=p%10-1;
            t+=z*y;
            p=p/10;
            y=y*10;
        }
        p=t%1000;
        a=b;
        b=p;
    }
    cout<<p;

    return 0;
}
