n, m = map(int, input().split())
ans = [0] * n

for _ in range(m):
    i, kk = map(int, input().split())
    if ans[i-1] == 0 or ans[i-1] == kk:
        ans[i-1] = kk
    else:
        ans[0] = 0
        break
    
if ans[0] == 0:
    print(-1)
else:
    ans = [str(s) for s in ans]
    print(''.join(ans))