N, M = map(int, input().split())
SC = [list(map(int, input().split())) for _ in range(M)]
D = {}
ans = ['0'] * N
ans[0] = '1'
for i in range(M):
    if SC[i][0] not in D:
        D[SC[i][0]] = SC[i][1]
    else:
        if D[SC[i][0]] != SC[i][1]:
            print(-1)
            exit()

for k, v in D.items():
    ans[k-1] = str(v)

ans = -1 if ans[0] == '0' else int(''.join(ans))
print(as)
