n, m = map(int, input().split())
s, c = [], []
for i in range(m):
    temp_s, temp_c = map(int, input().split())
    s.append(temp_s)
    c.append(temp_c)

ans = ['0'] * n

for i in range(m):
    if s[i] == 1 and c[i] == 0:
        print(-1)
        exit()
    if ans[s[i] - 1] == '0':
        str_c = str(c[i])
        ans[s[i] - 1] = str_c
    else:
        if ans[s[i] - 1] == str(c[i]):
            pass
        else:
            print(-1)
            exit()
if ans[0] == 0:
    ans[0] = '1'
print(int(''.join(ans)))
