n, m = list(map(int, input().split()))

s = [0] * m
c = [0] * m

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

result = [0] * n

for i in range(m):
    if result[s[i]-1] == 0:
      result[s[i]-1] = c[i]
    elif result[s[i]-1] > c[i]:
      result[s[i]-1] = c[i]

print(result)
if result[0] == 0:
    print(-1)
    exit()

ans = "".join(str(x) for x in result)
print(ans)