n, m = map(int, input().split())
ans = [-1 for _ in range(n)]
end_flag = False
for _ in range(m):
    s, c = map(int, input().split())
    if ans[s-1] == -1:
        ans[s-1] = c
    elif ans[s-1] == c:
        continue
    else:
        end_flag = True
        break
# print(ans)
if ans[0] == 0:
    end_flag = True
if ans[0] == -1:
    ans[0] = 1
if ans[1] == -1:
    ans[1] = 0
if ans[2] == -1:
    ans[2] = 0
# print(ans)
if end_flag:
    print(-1)
else:
    print('{}{}{}'.format(ans[0], ans[1], ans[2]))
