N,M = map(int,input().split())
sc = [list(map(int,input().split())) for i in range(M)]

# 辞書初期化3桁0埋め
dic = {}
for i in range(N):
    dic[i] = 0

# scの辞書化
dic2= {}
flg = False
for i in sc:
    if i[1] != 0:
        if (i[0]-1 not in dic2.keys()):
            dic2[i[0]-1] = i[1]
        elif (i[0]-1 in dic2.keys()) and (i[1] != dic2[i[0]-1]):
            flg = True

if flg == False:
    # update
    dic.update(dic2)

    s = ''
    for k,v in dic.items():
        s += str(v)

    if len(str(int(s))) == N:
        print(int(s))
    else:
        print(-1)
else:
    print(-1)