a=int(raw_input())
b=int(raw_input())
c=int(raw_input())
d=int(raw_input())
print pow(a,b)+pow(c,d)

a=int(raw_input())
b=int(raw_input())
c=int(raw_input())
d=int(raw_input())
print pow(a,b)+pow(c,d)
