s = []
ans = 0
flag = True
N, M = map(int, input().split())
for i in range(M):
    a = list(map(int, input().split()))
    if a not in s:
        s.append(a)
S = sorted(s)

for i in range(len(S)-1):
    if S[i][0]==S[i+1][0] and S[i][1]!=S[i+1][1]:
        flag = False

if N>1 and S[0]==[1,0]:
    flag = False

if flag == True:
    for i in range(len(S)):
        for j in range(N+1):
            if S[i][0]==j:
                ans+=S[i][1]*10**(N-j)
    print(ans)
            
else:
    print(-1)