#!/usr/bin/env python3
(n, _), *m = [[*map(int, i.split())] for i in open(0)]

a = [0] * n

for s, c in m:
    if a[s - 1] in (0,c):
        a[s - 1] = c
    else:
        print(-1)
        exit()
if a[-1] == 0:
    print(-1)
    exit()
print(int("".join([*map(str, a)])))
