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

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

for j in range(m):
    s[j], c[j] = 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]

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

ans = ""
for r in result:
    ans += str(r)
print(ans)