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

keta1set = set()
keta2set = set()
keta3set = set()

for i in range(m):
    s, c = int(input().split())
    if s == 1:
        keta1set.append(tuple([s, c]))
    elif s == 2:
        keta2set.append(tuple([s, c]))
    else:
        keta3set.append(tuple([s, c]))

dame = 0

if len(keta1set) >= 2 or len(keta2set) >= 2 or len(keta3set) >= 2:
    dame = 1

suuji = [keta1set, keta2set, keta3set]

def kara(shugo):
    if shugo == set():
        return True

if kara(suuji[n-1]):
    if suuji[n-1][0][1] == 0:
        dame = 1

def kekka(shugo):
    if kara(shugo):
        return "0"
    else str(shugo[1])

if dame == 1:
    print(-1)
else:
    res = ""
    for keta in range(n, -1, -1):
        res = res + kekka(suuji[keta])
    print(res)
