#!/usr/bin/env python3
N, M = map(int, input().split())

d = {}
max_keta = 0
for i in range(M):
    s, c = map(int, input().split())
    if s in d and c!=d[s]:
        print(-1)
        exit()
    else: d[s] = c
    if max_keta < s: max_keta = s


ans = -1
for num in range(1, 10**3+1):
    s = str(num)
    f = True
    if len(s) < max_keta: continue
    for keta, n in d.items():
        if s[keta-1]!=str(n):
            f = False
    if f:
        ans = s
        break

print(ans)
