n,m = map(int,input().split())

rest = []
for i in range(m):
    a,b = input().split()
    rest.apend((int(a),b))

done = False

for i in range(0,1000):
    x = str(i)
    if (len(x) == n):
        ok = True
        for t in rest:
            if (x[t[0] - 1] != t[1]):
                ok = False
                break
        if ok:
            print(i)
            done = True

if not done:
    print(-1)