# 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 = []

for i in range(N):
    ans.append("x")

isOK = False

for j in range(M):
    if ans[I[j][0] - 1] == str(I[j][1]) or ans[I[j][0] - 1] == "x":
        ans[I[j][0] - 1] = str(I[j][1])
    elif ans[I[j][0] - 1] != str(I[j][1]):
        ans = "-1"
        break

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)))
