n, m = map(int, input().split())
sc = [list(map(int, input().split())) for _ in range(m)]
ans = ['0'] * n
ans[0] = '1'
num = len(sc)
for i in range(num):
    ans[sc[i][0] - 1] = str(sc[i][1])
    for j in range(num - i - 1):
        if sc[i][0] == sc[i + j + 1][0] and not (sc[i][1] == sc[i + j + 1][1]):
            print('-1')
            exit()
print(''.join(ans))
