n,m = map(int, input().split())
xy = [map(int, input().split()) for _ in range(m)]
x, y = [list(i) for i in zip(*xy)]
ans = [0]*n
for i in range(m):
    ans[x[i]-1] = y[i]
t = 0
for i in range(m):
    if ans[x[i]-1] != y[i]:
        t = 1
if ans[0] == 0:
    print(-1)
else:
    for i in range(n):
        print(ans[i], end='')