import sys
input = lambda: sys.stdin.readline().rstrip()
input_nums = lambda: list(map(int, input().split()))

n, m = input_nums()
sc = []
for i in range(m):
    sc.append(tuple(input_nums()))

sc = list(set(sc))
sc.sort(key=lambda x: x[0])

check = {}
res = [1] + [0] * (n-1)
for s, c in sc:
    if not s in check.keys():
        check[s] = c
        res[s-1] = c
    else:
        if check[s] != c:
            res = -1
            break
if res == -1:
    print(res)
else:
    if len(res) != 1 and res[0] == 0:
        print(-1)
    elif res[0] == 0:
        print(0)
    else:
        res = map(str, res)
        print(''.join(res))