n, m = map(int, input().split())
anslist = [0]*(n+1)

ans = 10**6

for i in range(m):
    s, c = map(int, input().split())
    if (anslist[s] != 0) and (anslist[s] != c):
        ans = -1
    anslist[s] = c
if ans == -1 or anslist[1] == 0:
    print(-1)
else:
    ans = ''.join(map(str,anslist[1:]))
    print(ans)