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]:
            flg = False
            break
    di[sc1[0]] = sc1[1]
    s[sc1[0]-1] = str(sc1[1])
if (s[0] == "0"):
    if (n == 1):
        print(s[0])
    else:
        print("-1")
else:
    print("".join(s))