n , m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

#n,m = 3,3
#sc = [[2, 0],[2, 1],[3,0]]

ck = 1
x = [99] * (n+1)
for s,c in sc:
  if x[s] == 99:
    x[s] = c
  else:
    if x[s] != c:
      ck = 0
      break

x = [99] * (n+1)
for s,c in sc:
  x[s] = c
for i,data in enumerate(x):
  if data == 99:
    x[i] = 0

ans = 0
c = 1
for i in x[::-1]:
  ans += i * c
  c *= 10

if ck:
  print(ans)
else:
  print('-1')
