import sys
N,M = map(int,input().split())
P = []
for i in range (N):
    P.append(-1)

A=[] #appendのために宣言が必要
while True:
    try:
        A.append(list(map(int,input().split())))

    except:
        break;



for s in range(M):
    if P[A[s][0]-1]== -1 or P[A[s][0]-1] ==A[s][1]:
        P[A[s][0]-1] = A[s][1]
    else:
        print(-1)
        sys.exit()
if P[0] == -1:
    P[0]= 1
elif P[0] == 0 and N != 1:
    print(-1)
    sys.exit()
elif P[0] == 0 and N == 1:
    print(0)
    sys.exit()
for j in range(N):
    if P[j] == -1:
        P[j] = 0 
print("".join(map(str,P)))
    
