import sys
import numpy as np

# input = sys.stdin.readline

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

sc = [list(map(int, input().split())) for ii in range(m)]

s = []
for i in range(n):
    s.append("0")
flg = True
di = {}
for sc1 in sc:
    if sc1[0] in di:
        if di[sc1[0]] > sc1[1]:
            di[sc1[0]] = sc1[1]
            s[sc1[0]-1] = str(sc1[1])
    else:
        di[sc1[0]] = sc1[1]
        s[sc1[0]-1] = str(sc1[1])

if (flg == False):
    print("-1")
elif (n == 1):
    print("".join(s))
else:
    if (s[0] != 0):
        print("".join(s))
    else:
        print("-1")