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