N, M = map(int, input().split())
sc = [tuple(map(int, input().split())) for _ in range(M)]
f = [0] * N
ans = ['0'] * N
for s, c in sc:
  if (f[s - 1] and ans[s - 1] != str(c)) or (N != 1 and s == 1 and c == 0):
    print(-1)
    exit()
  elif N == 1 and s == 1 and c == 0:
    print(0)
    exit()
  else:
    ans[s - 1] = str(c)
    f[s - 1] = 1
    
if ans[0] == '0':
  ans[0] = '1'
print(''.join(ans))