from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
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()
dig = [None] * n
for i in range(m):
    j,c = inpl()
    if dig[j-1] == None:
        dig[j-1] = c
    elif dig[j-1] != c:
        print(-1)
        quit()
res = ''
for i,t in enumerate(dig):
    if i == 0:
        if t == 0:
            print(-1)
            quit()
        if t == None: res += '1'
        else: res += str(t)
        continue
    if t == None: res += '0'
    else: res += str(t)
print(res)