i=input n,s=int(input()),list(input()) n-=1 if [i==s.pop(0)for i in input()]else 0 print(n)