n, m = map(int, input().split())
s = []
c = []
for i in range(m):
    rets, retc = map(int, input().split())
    s.append(rets)
    c.append(retc)

check = False
ans = [-1] * 3
mi = 1000

for i in range(m):
    if ans[s[i] - 1] != -1:
        if ans[s[i] - 1] != c[i]:
            mi = -1
            break
    else:
        ans[s[i] - 1] = c[i]

if mi == -1:
    print(-1)
else:
    for i in range(3):
        if ans[i] == int(-1):
            ans[i] = 0
    if ans[0] == 0 and ans[1] == 0:
        print(-1)
    else:
        print(''.join(map(str, ans)))
