N, M = map(int, input().split())
sc = [list(map(int, input().split())) for i in range(M)]
cnt = 0
ans = []
if N == 1:
  for i in range(10):
    i = str(i)
    for j in range(M):
      if i[sc[j][0] - 1] == str(c = sc[j][1]):
        cnt += 1
    if cnt == M:
      ans.append(int(i))
    cnt = 0
else:
  for i in range(10**(N-1), 10**N):
    i = str(i)
    for j in range(M):
      if i[sc[j][0] - 1] == str(sc[j][1]):
        cnt += 1
    if cnt == M:
      ans.append(int(i))
    cnt = 0

#print(ans)
print(min(ans) if ans else -1)