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())
flag = [0] * N

ans = [0] * N
for i in range(M):
    if((s[i]==1) & (c[i]==0)):
        ans = -1
        print(-1)
        exit()
        break
    if(flag[s[i]-1] == 0):
        ans[s[i]-1] = c[i]
        flag[s[i]-1] = 1
    
    elif(c[i] != ans[s[i]-1]):
        ans = -1
        print(-1)
        exit()
        break
if(flag[0]==0):
    print(-1)
    exit()
a = 0
for i in range(N):
    a += ans[N-i-1]*10**i
print(a)