#include //#include const int FIB_PISANO_PERIOD_FOR_TEN = 60; static int getFibNModM(long n) { long r = n % FIB_PISANO_PERIOD_FOR_TEN; if (r == 0) return 0; int firstN = 0; int secondN = 1; int tempHolder = 1; for (int i = 1; i < r; i++) { tempHolder = (firstN + secondN) % 10; firstN = secondN; secondN = tempHolder; } return secondN; } static int getLastDigit(long n) { if (n <= 1) return (int) n; int result = getFibNModM(n + 2); if (result == 0) return 9; else return result - 1; } static int getLastDigit(long m, long n) { if (m == n) return getFibNModM(n); else { int sumFn = getLastDigit(n); int sumFm; if (m <= 1) sumFm = 0; else sumFm = getLastDigit(m - 1); if (sumFn >= sumFm) return sumFn - sumFm; else return sumFn - sumFm + 10; } } //TEST(FibPartialSumLastDigit, Ten_200) { // ASSERT_EQ(getLastDigit(10, 200), 2); //TEST(FibPartialSumLastDigit, One_2) { // ASSERT_EQ(getLastDigit(1, 2), 2); int main() { long m, n; std::cin >> m; std::cin >> n; int c = getLastDigit(m, n); std::cout << c << '\n'; }