import strutils, tables proc input: string = while true: let t = stdin.readChar if t.isSpaceAscii: break else: result.safeAdd t let n, m = input().parseInt var dic = initCountTable[string]() for i in 0 ..< m: dic.inc (i * 2 mod n).repr if (dic.len * 2) mod n != 0: echo -1 else: for m in countdown(m, 2): if n mod m == 0: echo n div m quit()