n, m = map(int, input().split())
s = []
c = []
for _ in range(m):
    a, b = map(int, input().split())
    s.append(a)
    c.append(b)


s_len = len(s)
ret = ['0'] * n
if m == 0:
    if n == 1:
        print(0)
    else:
        ret[0] = '1'
        print("".join(ret))
elif s[0] == 1 and c[0] == 0 and n != 1:
    print(-1)
else:
    flag = 1
    for i in range(m):
        if ret[s[i] - 1] == '0':
            ret[s[i] - 1] = str(c[i])
        else:
            if ret[s[i] - 1] != str(c[i]):
                print(-1)
                flag = 0
                break
    if flag:
        if ret[0] == '0':
            ret[0] = '1'
        print("".join(ret))