def main():
    N, M = map(int, input().split())
    num = [None for i in range(N)]

    for i in range(M):
        s, c = map(int, input().split())
        
        if num[s-1] == None:
            num[s-1] = c
        elif num[s-1] == c:
            pass
        else:
            print("-1")
            exit()

    for i in range(N):
        if num[i] == None:
            num[i] = 0
    
    if N == len(str(int("".join(map(str, num))))):
        print("".join(map(str, num)))
    else:
        print("-1")

if __name__ == "__main__":
    main()