N, M = map(int, input().split())

ans = [-1] * N
flag = True
for i in range(M):
    s, c = map(int, input().split())
    if ans[s - 1] != -1 and ans[s - 1] != c:
        print(-1)
        flag = False
        break
    ans[s - 1] = c

if ans[0] == 0:
    print(-1)
elif flag:
    for i in range(M):
        ans[i] = 0 if ans[i] == -1 else ans[i]
    ans_s = sum([ans[i] * 10 ** (N - i - 1) for i in range(N)])
    print(ans_s)