#include <bits/stdc++.h>
using namespace std;

int findCurrentNumber(int previous, int previousAfter)
{
    if(previous==0 || previousAfter==0)
    {
        return 9;
    }

    int numberStruct=previous*previousAfter;
    int numberZ=0;
    int ten=1;

    while(numberStruct!=0)
    {
        int currentDigits=numberStruct%10;

        if(currentDigits==0)
        {
            currentDigits=9;
        }
        else
        {
            currentDigits--;
        }

        numberZ+=ten*currentDigits;
        ten*=10;
        numberStruct/=10;
    }

    int currentNumber=numberZ%1000;

    return currentNumber;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    long long numberFind;
    int numberOne, numberTwo;
    cin >> numberFind >> numberOne >> numberTwo;

    int currentNumber;
    int previous=numberTwo, previousAfter=numberOne;

    for(int current=1; current<=numberFind; current++)
    {
        currentNumber=findCurrentNumber(previous, previousAfter);
        previousAfter=previous;
        previous=currentNumber;
    }

    cout << currentNumber;
    return 0;
}

