N, M = map(int, input().split())
lis = [0]*N
SC = []
ERROR = False
for _ in range(M):
  sc = list(map(int, input().split()))
  SC.append(sc)
for i in range(len(SC)-1):
  for j in range(i+1,len(SC)):
    if SC[i][0] == SC[j][0] and SC[i][1] != SC[j][1]:
      ERROR = True
if ERROR:
  print(-1)
else:
  output = ''
  for i in range(len(SC)):
    lis[SC[i][0]-1] = SC[i][1]
  if N > 1 and lis[0] == '0':
    print(-1)
  else:
    for i in range(N):
      output += str(lis[i])
    print(int(output))