N, M = map(int, input().split())

if N == 1:
  ans = "*"
elif N == 2:
  ans = "**"
else: #N==3
  ans = "***"

  
ng = False
for i in range(M):
  s, c = input().split()
  s = int(s)
  if ans[s] != '*' or ans[s] != c:
    ng = True
    break
  else:
    ans[s] = c

if N == 1 and ans == "*":
  ans = "0"
if N == 2:
  if ans[0] == "*":
    ans[0] = "1"
  if ans[1] == "*":
    ans[1] = "0"
if N == 3:
  if ans[0] == "*":
    ans[0] = "1"
  if ans[1] == "*":
    ans[1] = "0"
  if ans[2] == "*":
    ans[2] = "0"

if ng:
  print(-1)
else:
  print(int(ans))