n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]
ans = 0
num = [0]*n 
if sc[0][1] == 0:
    ans = -1
else:
    for i in range(n):
        if num[sc[i][0]-1] == 0 or num[sc[i][0]-1] == sc[i][1]:
            num[sc[i][0]-1] = sc[i][1]
        else:
            ans = -1
            break
if ans == 0:
    s = int("".join(map(str,num)))
    print(s)
else:
    print(ans)