# coding: utf-8
N, M = map(int, input().split())
d = {}
ans = ["0" for _ in range(N)]
for i in range(M):
    s, c = map(int, input().split())
    if s not in d.keys():
        d[s] = c
        ans[s-1] = str(c)
    else:
        if d[s] != c:
            ans = -1
            print(ans)
            exit()
ans = "".join(ans)
if ans[0] == "0" and 0 not in d.keys():
    ans[0] = "1"
print(ans)