# -*- coding: utf-8 -*-
N, M = map(int, input().split())

X = [-1 for i in range(N)]
flg = 0

for i in range(M):
  s,c = map(int, input().split())
  s -= 1
  if s==0 and c==0:
    print(-1)
    flg = 1
    break
  if X[s]==-1:
    X[s] = c
  elif X[s]!=c:
    print(-1)
    flg = 1
    break

if flg==0:
  if N==1:
    print(0, end='') if X[0]==-1 else print(X[0], end='')
  else:
    for i in range(N):
      print(max(0,1-i), end='') if X[i]==-1 else print(X[i], end='')