import numpy as np
N,M = map(int, input().split())
A = np.array([])

for i in range(M):
    A = np.append(A,input().split())
A = A.reshape([-1,2]).astype("int")
A_uni = np.unique(A, axis=0)
A_index_uni = np.unique(A[:,0], axis=0)
if A_uni.shape[0] != A_index_uni.shape[0]:
    Ans = "-1"
else:
    if (A_uni[:,0]==1).sum()>0:
        if A_uni[A_uni[:,0]==1][0][1]==0:
            Ans = "-1"
        else:
            Ans = list(str(10**(N-1)))
            for i in A_uni:
                Ans[i[0]-1] = str(i[1])   
            Ans = ''.join(Ans)
    else:
        Ans = list(str(10**(N-1)))
        for i in A_uni:
            Ans[i[0]-1] = str(i[1])
        Ans = ''.join(Ans)
print(Ans)