Buggy python submission (verdict: Runtime Error):
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)

result = ll
for i in xrange(n):
    if not (i*m) % n :
            tmp=i*m/n
            if s[i] != t[tmp] :
                result= -1
print result

Fixed submission:
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n/gg*m
result = ll
for i in xrange(n):
    if not (i*m) % n :
            tmp=i*m/n
            if s[i] != t[tmp] :
                result= -1
print result

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n/gg*m
aa=m/gg
bb=n/gg
ab=(m/gg)*(n/gg)
result = ll
i=0
while i < ll :
    if not (i % ab):
            tmp1=i/aa
            tmp2=i/bb
            if s[tmp1] != t[tmp2] :
                result= -1
    i+=1
print result

Fixed submission:
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n/gg*m
result = ll
for i in xrange(n):
    if not (i*m) % n :
            tmp=i*m/n
            if s[i] != t[tmp] :
                result= -1
print result

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n/gg*m
aa=m/gg
bb=n/gg
ab=(m/gg)*(n/gg)
result = ll
for i in xrange(ll) :
    if not (i % ab):
            tmp1=i/aa
            tmp2=i/bb
            if s[tmp1] != t[tmp2] :
                result= -1
print result

Fixed submission:
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n/gg*m
result = ll
for i in xrange(n):
    if not (i*m) % n :
            tmp=i*m/n
            if s[i] != t[tmp] :
                result= -1
print result

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n/gg*m
aa=m/gg
bb=n/gg
result = ll
for i in xrange(ll) :
    if not (i % aa):
        tmp1=i/aa
        if not(i % bb) :
            tmp2=i/bb
            if s[tmp1] != t[tmp2] :
                result= -1
print result


Fixed submission:
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n/gg*m
result = ll
for i in xrange(n):
    if not (i*m) % n :
            tmp=i*m/n
            if s[i] != t[tmp] :
                result= -1
print result

Buggy python submission (verdict: Runtime Error):
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n*m/gg
aa=ll/n
bb=ll/m
result = ll
for i in range(ll) :
    if not (i % aa):
        tmp1=i/aa
        if not(i % bb) :
            tmp2=i/bb
            if s[tmp1] != t[tmp2] :
                result= -1
print result


Fixed submission:
import fractions
nm=raw_input()
nm=nm.split()
n=eval(nm[0])
m=eval(nm[1])
s=raw_input()
t=raw_input()

gg=fractions.gcd(n,m)
ll=n/gg*m
result = ll
for i in xrange(n):
    if not (i*m) % n :
            tmp=i*m/n
            if s[i] != t[tmp] :
                result= -1
print result