#coding: utf-8 def main(): n, m = map(int, input().split(' ')) a = 1 for i in range(1, n + 1): a *= i print(a % m) if __name__ == '__main__': main()