N,M = map(int, input().split())
d = ['x']*N

flg = 0
for i in range(M):
  s,c = map(int, input().split())
  s -= 1
  if d[s] == 'x':
    d[s] = c
  if d[s] != c or (s==0 and c==0 and N>1):
    flg = -1

ans = 0
for j in range(N):
  N-=1
  if d[j]=='x':
    if j == 0:
      d[j] = 1
    else:
      d[j] = 0
  ans += d[j]*(10**N)

print(flg if flg == -1 else ans)