s, t = map(int, input().split())
u = [list(map(int, input().split())) for _ in range(t)]
ln = ['a'] * s
x = 0
for i in range(t):
    if ln[u[i][0] - 1] == 'a':
        ln[u[i][0] - 1] = u[i][1]
    if ln[u[i][0] - 1] != 'a' and ln[u[i][0] - 1] != u[i][1]:
        x += 1
if x >= 1:
    print(-1)
elif ln[0] == 0:
    print(-1)
else:
    if ln[0] == 'a':
        ln[0] = 1
    ln = [str(a) for a in ln]
    ln = ''.join(ln)
    print(ln.replace('a', '0'))