This page is still under construction.

Parts of this page are still being built. What you see may change.

Explosive Materials

Interview

Time limit3sMemory limit256 MB

Summary
Split conflicting materials into two safe boxes and minimize the fuller box size.
Level

Medium5 of 10

Topics
Graph, BFS, Dynamic programming
Solved
No attempts yet

Problem

Erik is sending samples of nn kinds of material to his laboratory for a purity analysis. The kinds are numbered 1 to nn. He packs the samples into boxes of equal capacity. A box has capacity cc if it holds up to cc kinds of material.

Some materials react and explode, so they cannot go in the same box. Erik found that if putting kk kinds a1,…,aka_1, \dots, a_k in one box explodes, then putting any two of them in one box explodes as well. He wrote down every pair that explodes, and the list has mm pairs.

Because every explosion comes from a pair, Erik wants to know whether two boxes of equal capacity are enough. All nn kinds must be split between the two boxes, and no two materials in the same box may form a pair from the list. If that is possible, what is the smallest capacity of a box?

Input

The first line contains the number of test cases TT (T≤20T \le 20).

The first line of each test case contains two integers nn and mm (1≤n≤10001 \le n \le 1000, 0≤m≤min⁡(n(n−1)/2, 105432)0 \le m \le \min(n(n-1)/2,\ 105432)), the number of kinds of material and the number of pairs on the list. Each of the next mm lines contains two integers aa and bb (1≤a,b≤n1 \le a, b \le n, a≠ba \ne b), meaning that material aa and material bb explode when they are put in the same box. No pair is listed twice.

Output

For each test case, print one integer on its own line. Print -1 if the materials cannot be sent in two boxes. Otherwise print the smallest capacity of a box.

Examples4

  1. Example 1

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

    Input
    1
    1 0
    
    Expected output
    1
    
  3. Example 3

    Input
    1
    7 0
    
    Expected output
    4
    
  4. Example 4

    Input
    1
    2 1
    1 2
    
    Expected output
    1