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