Under construction

Still being built. Things may change

Job Assignment 2

Time limit4sMemory limit256 MB

Summary
Assign each of M jobs to one of N employees who can do it with at most two jobs per employee to handle as many jobs as possible.
Level

Medium4 of 10

Topics
Graph, BFS, DFS
Solved
No attempts yet

Problem

Kangho's company has NN employees and MM jobs to handle. Employees are numbered 1 to NN, and jobs are numbered 1 to MM.

Each employee can take at most two of the jobs that employee is able to do, and each job is taken by exactly one person.

Given the list of jobs each employee is able to do, write a program that finds how many of the MM jobs can be handled at most.

Input

The first line contains the number of employees NN and the number of jobs MM. (1≤N,M≤10001 \le N, M \le 1000)

Each of the next NN lines describes one employee. The ii-th of these lines contains the number of jobs employee ii is able to do, followed by the numbers of those jobs.

Output

Print the maximum number of jobs Kangho's company can handle on the first line.

Examples6

  1. Example 1

    Input
    5 5
    2 1 2
    2 1 2
    2 1 2
    2 4 5
    0
    
    Expected output
    4
    
  2. Example 2

    Input
    1 1
    1 1
    
    Expected output
    1
    
  3. Example 3

    Input
    1 1
    0
    
    Expected output
    0
    
  4. Example 4

    Input
    2 5
    5 1 2 3 4 5
    5 1 2 3 4 5
    
    Expected output
    4
    
  5. Example 5

    Input
    3 2
    2 1 2
    2 1 2
    2 1 2
    
    Expected output
    2
    
  6. Example 6

    Input
    6 6
    2 1 2
    2 2 3
    2 3 4
    2 4 5
    2 5 6
    2 6 1
    
    Expected output
    6