#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;

    if(numberFind==1)
    {
        cout << numberOne;
        return 0;
    }
    else if(numberFind==2)
    {
        cout << numberTwo;
        return 0;
    }

    vector<pair<int, int>> pairs;
    vector<int> numbers;
    long long indexStart, indexEnd;

    bool isOver=false;

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

        pairs.push_back({previous, previousAfter});
        numbers.push_back(currentNumber);

        for(int index=0; index<pairs.size()-1; index++)
        {
            if(previous==pairs[index].first && previousAfter==pairs[index].second || previousAfter==pairs[index].first && previous==pairs[index].second)
            {
                indexStart=index;
                isOver=true;
                break;
            }
        }

        if(isOver)
        {
            break;
        }

        previousAfter=previous;
        previous=currentNumber;

        if(current==numberFind)
        {
            cout << currentNumber;
            return 0;
        }
    }

    vector<int> povt;

    for(int index=indexStart; index<numbers.size()-1; index++)
    {
        povt.push_back(numbers[index]);
    }

    numberFind-=2;
    numberFind-=indexStart;
    numberFind%=povt.size();

    if(numberFind==0)
    {
        cout << povt[povt.size()-1];
    }
    else
    {
        cout << povt[numberFind-1];
    }
    return 0;
}