import itertools
n, m = map(int, input().split())
memo = dict()
ans = 100000000
arr = [0] * 10
memo = [0] * n
for _ in range(m):
  s, c = map(int, input().split())
  if arr[s]==0:
    arr[s] = c
    memo[s-1]=c
  if arr[s]!=0 and arr[s]!=c:
    ans=-1
  
if memo[0]==0:
  ans=-1
else:
  ans = ""
  for m in memo:
    ans += str(m)
print(ans)
