# coding: utf-8
n = list(map(int, input().split()))
N, M = n[0], n[1]

# 複数行標準入力
I = []
for _ in range(M):
    I.append(list(map(int, input().split())))

ans = ["x", "x", "x"]

for j in range(len(I)):
    for k in range(j + 1, len(I)):
        if I[j][0] == I[k][0] and I[j][1] != I[k][1]:
            ans = "-1"
            break
        else:
            ans[int(I[j][0]) - 1] = str(I[j][1])

if ans[0] == "x" or ans[0] == "0":
    del ans[0]
    if ans[0] == "x" or ans[0] == "0":
        del ans[0]
        if ans[0] == "x" or ans[0] == "0":
            ans = "-1"

for l in range(len(ans)):
    if ans[l] == "x":
        ans[l] = "0"

print(int(''.join(ans)))
