N,M=map(int,input().split())
List=[list(map(int,input().split())) for i in range(M)]
flag=True
for i in range(M):
    for j in range(i,M):
        if List[i][0]==List[j][0] and List[i][1]!=List[j][1]:
            print(-1)
            flag=False
            break
    if not flag:
        break

if N!=1 and [1,0] in List:
    print(-1)
    flag=False

if flag:
    ans=[0 for i in range(N)]
    for i in range(M):
        ans[List[i][0]-1]=List[i][1]
    if ans[N-1]==0:
        ans[N-1]=1

    print(sum(ans[j]*(10**(N-j-1)) for j in range(N)))