#coding:utf-8

n,m = map(int,input().split())

ans = -1
gl = 0
lists = []
listc = []
number = []
for i in range(n):
  number.append(0)

for i in range(m):
  s,c = map(int,input().split())
  if(number[s-1] != 0 and number[s-1] != c):
    number[0] = 0
    gl = -1
    break
  number[s-1] = c

for i in range(n):
  if(number[0] == 0):
    gl = -1
    break
  c = number[i]
  gl += c * 10 ** (n - i - 1)
  
print("{}".format(gl))