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

ans = [None] * 3

for _ in range(m):
    s, c = map(int, input().split())
    if s == 0 and c == 0:
        print(-1)
    if ans[s-1] is None:
        ans[s-1] = c
    elif ans[s-1] != c: 
        print(-1)

ans = [x or 0 for x in ans]

ans = list(map(str, ans))

print(''.join(ans))