def main():
    N,M=map(int, input().split())
    ANS = [0]*N
    BOO = [False]*N
    for _ in range(M):
            s,c=map(int, input().split())
            if BOO[s-1] and c!=ANS[s-1]:
                print(-1)
                return
            if s-1 == 0 and c == 0:
                print(-1)
                return
            ANS[s-1] = c
            BOO[s-1] = True
        
    if ANS[0] == 0:
        ANS[0] = 1
    
    print(''.join([str(n) for n in ANS]))
    
    
if __name__ == '__main__':
    main()