4. In the Empire of Westeros, there were 1000 cities and 2017 roads (each road connected some two cities). From any city, you could travel to any other. One day, an evil wizard enchanted $N$ roads, making it impossible to travel on them. As a result, 7 kingdoms formed, such that within each kingdom, you could travel from any city to any other by roads, but you could not travel from one kingdom to another by roads. What is the largest $N$ for which this is possible?