#AGC004F. [AGC004F] Namori

[AGC004F] Namori

Score : 22002200 points

Problem Statement

You are given an undirected graph with NN vertices and MM edges. Here, N1MNN-1 \leq M \leq N holds and the graph is connected. There are no self-loops or multiple edges in this graph.

The vertices are numbered 11 through NN, and the edges are numbered 11 through MM. Edge ii connects vertices aia_i and bib_i.

The color of each vertex can be either white or black. Initially, all the vertices are white. Snuke is trying to turn all the vertices black by performing the following operation some number of times:

  • Select a pair of adjacent vertices with the same color, and invert the colors of those vertices. That is, if the vertices are both white, then turn them black, and vice versa.

Determine if it is possible to turn all the vertices black. If the answer is positive, find the minimum number of times the operation needs to be performed in order to achieve the objective.

Constraints

  • 2N1052 \leq N \leq 10^5
  • N1MNN-1 \leq M \leq N
  • 1ai,biN1 \leq a_i,b_i \leq N
  • There are no self-loops or multiple edges in the given graph.
  • The given graph is connected.

Partial Score

  • In the test set worth 15001500 points, M=N1M=N-1.

Input

The input is given from Standard Input in the following format:

NN MM

a1a_1 b1b_1

a2a_2 b2b_2

::

aMa_M bMb_M

Output

If it is possible to turn all the vertices black, print the minimum number of times the operation needs to be performed in order to achieve the objective. Otherwise, print -1 instead.

6 5
1 2
1 3
1 4
2 5
2 6
5

For example, it is possible to perform the operations as shown in the following diagram:

3 2
1 2
2 3
-1

It is not possible to turn all the vertices black.

4 4
1 2
2 3
3 4
4 1
2

This case is not included in the test set for the partial score.

6 6
1 2
2 3
3 1
1 4
1 5
1 6
7

This case is not included in the test set for the partial score.