n,m = map(int,input().split())
d = [-1 for _ in range(n)]
for i in range(m):
  si,ci = map(int,input().split())
  if d[si-1] == -1:
    d[si-1] = ci
  elif d[si-1] != ci:
    print(-1)
    exit()
if n == 1 and d[0] == 0:
  print(0)
  exit()
s = 0
if d[0] == 0:
  print(-1)
  exit()
if d[0] == -1:
  s += 1*10**(n-1)
else:
  s += d[0]*10**(n-1)
for i in range(1,n):
  if d[i] != -1:
    s += d[i]*10**(n-i-1)
print(s)
