n, m = (int(x) for x in input().split())
s = []
c = []
for _ in range(m):
    sc = [int(x) for x in input().split()]
    s.append(sc[0])
    c.append(sc[1])
num = 0
for nn in range(1, n + 1):
    for mm in range(m):
        if s[mm] == nn:
            if num // 10 ** (nn - 1) == 0:
                num += c[mm] * 10 ** (nn - 1)
            elif num // 10 ** (nn - 1) == c[mm]:
                continue
            else:
                print(-1)
                exit()
num = int(str(num)[::-1])
if len(str(num)) == n:
    print(num)
else:
    print(-1)