# -*- coding: utf-8 -*-

N, M = map(int,input().split())

ans=[ set() ]
for i in range(N):
        ans.append(set())

for i in range(M):
        s, c = map(int,input().split())
        ans[s].add(c)

st=''
for i in range(1,N+1):
        if len(ans[i]) == 1:
                n=ans[i].pop()
                if (i==1) and (n==0) and (N!=1):
                        st='-1'
                        break
                st+=str(n)
        elif len(ans[i]) == 0:
                if (N==1):
                        st+='1'
                else:
                        st+='0'
        else:
                st='-1'
                break

print(st)