o = input().split()
n = int(o[0])
m = int(o[1])
ans = ""
r = []
res = ""
for i in range(n):
  r.append("0")

for i in range(m):
  p = input().split()
  if not r[int(int(p[0])-1)] == "0" and  not r[int(int(p[0])-1)] == p[1]:
    ans = "-1"
  r[int(int(p[0])-1)] = p[1]

if not ans == "-1":
  for i in range(len(r)):
    res = res + r[i]
  ans = res
  
print(ans)