n, m = map(int, input().split())
s = [0] * m
c = [0] * m

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

flg = [0] * n
ans = [0] * n

for i in range(m):
    if flg[s[i]-1] == 0:
        ans[s[i]-1] = c[i]
        flg[s[i]-1] = 1
    elif flg[s[i]-1] != 0 and ans[s[i]-1] != c[i]:
        print(-1)
        exit()
    elif flg[s[i]-1] != 0 and ans[s[i]-1] == c[i]:
        pass

for i in range(n):
    if flg[i] == 0 and i == 0:
        ans[i] = 1

if ans[0] == 0 and n == 1:
    print(0)
elif ans[0] == 0 and len(ans) > 1:
    print(-1)
    exit()

flg_str = [str(i) for i in flg]
ans_str = [str(i) for i in ans]

print(''.join(ans_str))