n, m = map(int, input().split())
T = []
A = [str(0) for _ in range(n)]
for i in range(m):
  s, t = map(int, input().split())
  T.append([s, t])
if n > 1 and m == 0:
    print(-1)
    exit()

for i in range(m):
  for j in range(i, m):
    if (T[i][0] == T[j][0] and T[i][1] != T[j][1]) or (T[i][0] == 1 and T[i][1] == 0):
      print(-1)
      exit()
for i in range(0, 1000):
    a = str(i)
    f = True
    for j in range(m):
        s = T[j][0]
        c = T[j][1]
        if len(a) < s or a[s-1] != str(c):
            f = False
            break
    if f:
        print(a)
        break
