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

    num = [-1] * N
    for _ in range(M):
        s, c = map(int, input().split())
        if num[s-1] == -1:
            num[s-1] = c
        elif num[s-1] != c:
            print("-1")
            exit()
        
    if num[0] == -1 or num[0] == 0:
        print("-1")
    else:
        num = [0 if v == -1 else v for v in num]
        print(''.join(map(str,num)))

if __name__ == '__main__':
    main()