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

sc.sort(key=lambda x: x[0],reverse=True)
ans = ['0'] * n
now = -1
for i in sc:
    if ans[i[0]-1] != '0' and ans[i[0]-1] != str(i[1]):
        print(-1)
        quit()
    ans[i[0]-1] = str(i[1])
    now = i[0]

ans = str(int(''.join(ans)))
if len(ans) != n:
    print(-1)
else:
    print(ans)