from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
from decimal import Decimal
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
x = [-1] * n
for i in range(m):
    s,c = inpl()
    if x[s-1] == -1 or x[s-1] == c: 
        x[s-1] = c
    else:
        print(-1)
        quit()
# print(x)
if n == 1 and m == 0:
    print(0)
    quit()
res = -1
for i in range(1,1001):
    if len(str(i)) != n:
        continue
    ok = True
    for j,t in enumerate(str(i)):
        if x[j] == -1 or x[j] == int(t):
            continue
        ok = False
    if ok:
        res = i
        break
print(res)