n, m = map(int, input().split())
s, c = [], []

for _ in range(m):
    tmp1, tmp2 = map(int, input().split())
    s.append(tmp1)
    c.append(tmp2)

import numpy as np

ans = np.zeros(n)

kizon = {}
flag = True
for ss, cc in zip(s, c):
    if ss in kizon:
        if kizon[ss] != cc:
            flag = False
            break
    elif ss>n:
        flag = False
        break
    kizon[ss] = cc
    ans[ss-1] = cc

if ans[0]==0:
    flag = False

if flag:
    if len(ans)==3:
        print(int(ans[0]*100+ans[1]*10+ans[2]))
    elif len(ans)==2:
        print(int(ans[0]*10+ans[1]))
    else:
        print(int(ans[0]))
else:
    print(-1)