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