#Guess The Number https://atcoder.jp/contests/abc157/tasks/abc157_c
N,M = map(int,input().split())
Num_List = [[] for i in range(N)]
for i in range(M):
    Keta,Rule = map(int,input().split())
    Num_List[Keta-1].append(Rule)

for k in range(N):
    Num_List[k]=list(set(Num_List[k]))

Answer=""
for m in range(N):
    Length = len(Num_List[m])
    if Length == 0:
        if m == 0:
            Answer += "1"
        else:
            Answer += "0"
    elif Length == 1:
        if (m == 0) & (Num_List[m][0] == 0):
            Answer = "-1"
            break
        else:
            Answer += str(Num_List[m][0])
    else:
        Answer = "-1"
        break

print(int(Answer))