N,M = list(map(int, input().split()))
S,C,uniques=[],[],[]

if N==1:
    ans=['1']
elif N==2:
    ans=['1','0']
elif N==3:
    ans=['1','0','0']


for _ in range(M):
    s,c = list(map(int, input().split()))
    S.append(s)
    C.append(c)
    uniques.append(str(s)+str(c))
    ans[s-1]=str(c)

if len(S)!=len(list(set(S))):
    if len(list(set(uniques)))!=len(list(set(S))):
        ans='-1'

if ans[0]=='0':
    # print('a')
    ans='-1'

if type(ans)==str:
    print(int(ans))
else:
    print(int(''.join(ans)))