N, M = map(int, input().split())
S = [[0, 0] for _ in range(M)]
for i in range(M):
    S[i][0],S[i][1] = map(int, input().split())
    
num = sorted(S, key=lambda x:x[0])

if(M>0):
    if(num[0][1] > 0):
        ans = (10**(N-1))*num[0][1]
        for i in range(1, len(num)):
            if(num[i][0] == num[i-1][0]):
                if(num[i][1] != num[i-1][1]):
                    ans = -1
                    break
                continue
            ans += (10**(N-num[i][0]))*num[i][1]
        print(ans)
    else:
        print(0 if N==1 else -1)
else:
    if(N > 1):
        print(10**(N-1))
    else:
        print(0)