import sys
n,m=map(int,input().split())
ans=dict()

for _ in range(m):
    s,c=map(int,input().split())
    if not s in ans.keys():
        ans[s]=c
    else:
        if ans[s] != c:
            print(-1)
            sys.exit()
st=[]

if 1 in ans.keys():
    if ans[1] == 0:
        print(-1)
        sys.exit()
    else:
        st.append(str(ans[1]))
else:
    st.append("1")
    
for i in range(2,n+1):
    if i in ans.keys():
        st.append(str(ans[i]))
    else:
        st.append("0")
if st[0] == "0":
    print(-1)
    sys.exit()
else:
    print("".join(st))