def main():
    import sys
    import math
    import collections
    def input():
        return sys.stdin.readline()[:-1]
    N,M=map(int,input().split())
    sc=[list(map(int,input().split())) for _ in range(M)]
    answer=[0]*N
    check=[]
    if [1,0] in sc and N!=1:
        print(-1)
        sys.exit()
    for i in range(M):
        if sc[i][0] in check:
            if answer[sc[i][0]-1]!=sc[i][1]:
                print(-1)
                sys.exit()
        answer[sc[i][0]-1]=sc[i][1]
        check.append(sc[i][0])
    if answer[0]==0:
        answer[0]=1   
    x=0
    for j in range(N):
        x+=answer[j]*(10**(N-j-1))
    print(x)
if __name__ == '__main__':
    main()

