n, m = map(int, input().split())
s = [0]*m
c = [0]*m

for i in range(m):
  s[i], c[i] = map(int, input().split())

z = [0]*m
r = [0]*m
for i in range(m):
  r[s[i] - 1] = c[i]
  if s.count(s[i]) > 1:
    z[i] = i

if c[z[0]] != c[z[1]]:
  print(-1)
  exit()

if m >= 3:
  ans = r[0]*100 + r[1]*10 + r[2]*1
elif m == 2:
  ans = r[0]*10 + r[1]*1
else:
  ans = r[0]
print(ans)
