n, m = list(map(int, input().split())) a = list(map(int, input().split())) b = list(map(int, input().split())) def check (): res = 1 for i in range(n): for j in range(m): if a[i] == b[j]: print(res) return res += 1 print(-1) check()