# -*- coding: utf-8 -*-
import sys

N, M = map(int, input().split())
s = [0]*M
c = [0]*M
ans = [-1]*N
for i in range(M):
  s[i], c[i] = map(int, input().split())

for i in range(M):
  if(s[i] == 1 and c[i] == 0):
    print('-1')
    sys.exit()
  elif(ans[s[i]-1] != -1 and c[i] != ans[s[i]-1]):
    print('-1')
    sys.exit()
  else:
    ans[s[i]-1] = c[i]

for i in range(N):
  if(ans[i] == -1):
    ans[i] = 0

num = 0
for i in range(N):
  num += ans[i] * 10**(2-i)

print(int(num))
