N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]
 
s = [sc[i][0] for i in range(len(sc))]
c = [sc[i][1] for i in range(len(sc))]
 
judge=False
for i in range(len(s)):
    for j in range(len(s)):
        if s[i]==s[j] and c[i] != c[j]:
            print(-1)
            judge=True
            break
        break
 
 
 
 
target = [0 for i in range(N)]
 
if N != 1 and target[0]==0:
    target[0]=1
 
for i in range(M):
    target[sc[i][0]-1] = sc[i][1]
 
if judge==False:
    res=0
    for i in range(N):
        res = res + target[i]*(10**(N-i-1))
    print(res)