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

s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = map(int, input().split())

num = ['1'] * N
k = 0


for i in range(M):
    if  s[i] == 1 and c[i] == 0:
        print('-1')
        sys.exit()

for j in range(M):
    for k in range(M-j-1):
        k += 1
        if s[j] == s[j+k] and c[j] != c[j+k]:
            print('-1')
            sys.exit()
    
for l in range(M):
    num[s[l]-1] = str(c[l])

ans = ''
for n in range(N):
    ans += str(num[n])

print(ans)