N,M = map(int,input().split())
N_list = [0]*N
flg_list  = [0]*N
flg = False
for i in range(M):
    s,c = map(int,input().split())
    if flg_list[s-1] == 0:
        N_list[s-1] = c
        flg_list[s-1] = 1
    elif N_list[s-1] != c:
        flg = True
        break
if flg:
    print("-1")
else:
    res = 0

    for i in range(N-1,-1,-1):
        res += (10**i)*N_list[N-1-i]
    if  N != len(str(res)):
        print("-1")
    else:
        print(res)
