n,m = map(int,input().split())
sc = [list(map(int,input().split())) for _ in range(m)]

ans = [0]*n
judge_s = 0
judge_c = 0
sc = sorted(sc)
for i in range(m):
    if judge_s == sc[i][0] and judge_c != sc[i][1]:
        ans = -1
        break
    judge_s = sc[i][0]
    judge_c = sc[i][1]
    ans[sc[i][0]-1] = sc[i][1]


if ans != -1:
    if ans[0] == 0:
        ans = -1
    else:
        ans_ = ans.copy()
        ans = 0
        for i in range(n):
            ans += ans_[i]*10**(n-i-1)
    
print(ans)