n, m = map(int, input().split())
scs = [list(map(int, input().split())) for _ in range(m)]
ans = ['0'] * n
jdgmt = 0
for i in range(m):
    if ans[scs[i][0] - 1] == '0' or ans[scs[i][0] - 1] == str(scs[i][1]):
        ans[scs[i][0] - 1] = str(scs[i][1])
    else:
        jdgmt = -1
if jdgmt == -1 or ans[0] == '0':
    print(-1)
else:
    print(''.join(ans))
