from collections import Counter,defaultdict,deque
from bisect import bisect_left
import sys,math,itertools,pprint,fractions
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()
c = [None] * n
for i in range(m):
    a,b = inpl()
    if a == 1 and b == 0:
        print(-1)
        quit()
    if c[a-1] == None:
        c[a-1] = b
    elif c[a-1] != b:
        print(-1)
        quit()
res = ''
for i in c:
    if i == None:
        res += '0'
    else:
        res += str(i)
print(int(res))