N,M = map(int, input().split()) if N>2: print(0) exit() S1 = input() S2 = input() ANSSET = set() T1 = S1[0]+S2 if T1[:M]==S1: ANSSET.add(T1) T2 = S2[0]+S1 if T2[:M]==S2: ANSSET.add(T2) if len(ANSSET)>0: print(len(ANSSET)) exit() for i1 in range(M): if S1[i1]!=S2[i1]: break for i2 in reversed(range(M)): if S1[i2]!=S2[i2]: break if i1==i2: print(1) else: print(0)