#!/usr/bin/env python3
n, m = map(int, input().split())
s = [-1 for _ in range(m)]
c = [-1 for _ in range(m)]
for i in range(m):
    s[i], c[i] = map(int, input().split())

for x in range(1000):
    keta = 1 
    nx = x/10
    d = []
    while nx: 
        keta += 1
        d.append(nx%10)
        nx /= 10
    if keta != n:
        continue
    ok = True
    d = d[::-1]
    for i in range(m):
        if d[s[i]-1] != c[i]:
            ok = False
    if ok: 
        print(x)
        exit(0)

print(-1)
