m@main=getLine>>=print.f.words>>m f[x,y]=head[z|z<-[2..],read x==foldl1(((+).)(*z))[read[w]|w<-y]]