N, M = map(int, input().split())

flag = 0
x = [1000] * N
for m in range(M):
  s, c = map(int, input().split())
  if (x[s-1] != -1) & (x[s-1] != c):
    #flag = 1
    #pass
    if (s == 1) & (c == 0) & (N != 1):
      pass
    else:
      x[s-1] = x[s-1] if x[s-1] < c else c
  else:
    x[s-1] = c
#print(x)
    
ans = 0
for n in range(N):
  if x[n] != 1000:
    ans += 10**(N-n-1) * x[n]
#print(ans)

if (N == 1) & (M > 0) & (flag == 0):
  print(ans)
elif (ans >= 10**(N-1)) & (flag == 0):
  print(ans)
else:
  print(-1)