Network Reliability
A young company employee was assigned the task of designing a project for a reliable subnet consisting of N computers. Prioritizing reliability, the employee proposed a design where each computer is connected by a cable to every other computer. This means each computer would require N-1 network cards, and a total of N*(N-1)/2 cables would be laid out. When the department head reviewed the project and its cost estimate, he was initially taken aback. However, after the employee explained the reliability benefits, the head agreed to proceed with the project. All the cables were installed, the necessary equipment was purchased, and the network became operational. Later, the department head realized that all computers, including his own, were directly connected to the computer that provided Internet access. Concerned about the risk of his computer quickly becoming infected with viruses, he instructed the employee to remove the minimum number of cables necessary so that the shortest path (in terms of the number of cables) between his computer and the network computer would be exactly M.
Your task is to help the employee determine the exact number of cables that need to be removed.
Input
The first line contains two integers separated by at least one space: N and M, where (1 ≤ N ≤ 10000, 1 ≤ M ≤ N).
Output
The output should be a single integer representing the number of cables to be removed. If it is impossible to achieve a distance of M under the given conditions, output -1.