N, M = list(map(int, input().split()))

s = [0] * M
c = [0] * M
for i in range(M):
    s[i], c[i] = list(map(int, input().split()))

for i in range(1,4):
    index_num = [n for n, v in enumerate(s) if v == i]

    if (index_num == []): continue

    same_index_vals = []
    for j in index_num:
        same_index_vals.append(c[j])
    if(len(set(same_index_vals)) != 1):
        print('-1')
        exit()

for i in range(M):
    if(s[i] == 1 and c[i] == 0):
        print('-1')
        exit()

ans = ['N'] * 3
for i in range(M):
    ans[s[i] - 1] = c[i]


for i in range(M):
    if(ans[i] == 'N'):

        if(i == 0): ans[i] = 1
        else: ans[i] = 0

anss = ''
for i in range(len(ans)):
    anss += str(ans[i])

print(anss)