# -*- coding: utf-8 -*-
n, m = map(int, input().split())
d = [tuple(map(int, input().split())) for i in range(m)]
ans = [-1] * n
if (n > 1 and (1, 0) in d):
    print(-1)
    exit()

for i in d:
    s, c = i
    if ans[s - 1] == -1:
        ans[s - 1] = c
    elif ans[s - 1] == c:
        pass
    else:
        print(-1)
        exit(0)

for i, j in enumerate(ans):
    if i == 0:
        if j == -1:
            ans[i] = 1
        else:
            pass
    else:
        if j == -1:
            ans[i] = 0
        else:
            pass

print(int(''.join(map(str, ans))))
