import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,M = map(int, readline().split())

    if M >= 4:
        print(-1)
        exit()
    
    ans = [None]*N
    for i in range(M):
        s, c = map(int, readline().split())
        if ans[s-1] is None:
            ans[s-1] = c
        elif c == ans[s-1]:
            continue        
        else:
            print(-1)
            exit()
    
    for i in range(N):
        if ans[i] is None:
            ans[i] = 0

    if N >= 2 and ans[0] == 0:
        print(-1)
        exit()

    print("".join(map(str,ans)))

if __name__ == "__main__":
    main()
