s = input().split()

N = int(s[0])
M = int(s[1])
SN = [-1 for i in range(N)]
Ans = 0

for i in range(M):
  s = input().split()
  si = int(s[0])
  ci = int(s[1])
  if SN[si-1] == -1:
    SN[si-1] = ci
  elif SN[si-1] != ci:
    Ans = -1
if Ans == -1:
  print(-1)
  exit()
for i in range(N):
  if SN[i] == -1:
    SN[i] = 0
  Ans += SN[i] * (10 ** (N-1-i))

#print(SN)
if N > 1 and SN[0] == 0:
  print(-1)
else:
  print(Ans)