N, M = map(int,input().split())
ans = [-1]*N
flag_memo = [[0]*10 for x in range(N)]

for i in range(M):
    s, c = map(int,input().split())
    flag_memo[s-1][c] = 1

for i in range(N):
    if sum(flag_memo[i]) > 1 or flag_memo[0][0]==1:
        flag = -1
        break;
    else:
        if i == 0:
            if sum(flag_memo[0])==0:
                ans[0]=1
            else:
                ans[i]=flag_memo[i].index(1)
        else:
            if sum(flag_memo[i])==0:
                ans[i]=0
            else:
                ans[i]=flag_memo[i].index(1)

if flag == -1:
    print(-1)
else:
    ans_str = ""    
    for i in range(N):
        ans_str = ans_str + str(ans[i])
    print(ans_str)
