from functools import reduce a,b,c,d=map(int,input().split()) print(reduce(lambda x,y:x*y%d,[a,b,c])%d)