import sys
N,M = map(int,input().split())
ans = [0]*N
for x in range(M):
    a,b = map(int,input().split())
    if(ans[a-1]==0):
        ans[a-1] = b
    elif(ans[a-1]== b):
        ans[a-1] = b
    else:
        print(-1)
        sys.exit()
l = "".join([str(n) for n in ans])
int_l = int(l)
len_l = len(str(int_l))
if(len_l != N):
    print(-1)
else:
    print(int_l)