# python3


def last_digit_of_fibonacci_number_naive(n):
    assert 0 <= n <= 10 ** 6

    if n <= 1:
        return n

    return (last_digit_of_fibonacci_number_naive(n - 1) + last_digit_of_fibonacci_number_naive(n - 2)) % 10


def last_digit_of_fibonacci_number(n):
    assert 0 <= n <= 10 ** 6

    if n <= 1:
        return n
    x_lastDig=0
    y_lastDig=1
    z_lastDig=(x_lastDig + y_lastDig)%10
    for i in range(2,n+1):
        z_lastDig = (x_lastDig + y_lastDig) % 10
        x_lastDig = y_lastDig
        y_lastDig = z_lastDig
    return z_lastDig


if __name__ == '__main__':
    input_n = int(input())
    print(last_digit_of_fibonacci_number(input_n))
