// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <iomanip>
#define dibs reserve
#define OVER9000 1234567890
#define patkan 9
#define tisic 47
#define soclose 1e-9
#define pi 3.1415926535898
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define chocolate win
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):(x))
#define uint unsigned int
// mylittlepony
using namespace std;

int N,M;
vector< vector< pair<int,int> > > G;

bool bipar(int k) { // len prvych k (< k)
	vector<int> part(N,-1);
	queue<int> q;
	for(int i =0; i < N; i++) if(part[i] == -1) {
		q.push(i);
		part[i] =0;
		while(!q.empty()) {
			int a =q.front();
			ALL_THE(G[a],it) if(it->ss < k && part[it->ff] == -1) {
				part[it->ff] =1-part[a];
				q.push(it->ff);}
			q.pop();}
		}
	for(int i =0; i < N; i++) ALL_THE(G[i],it)
		if(part[i] == part[it->ff] && it->ss < k) return false;
	return true;}

int main() {
	cin.sync_with_stdio(0);
	cin >> N >> M;
	G.resize(N);
	for(int i =0; i < M; i++) {
		int a,b;
		cin >> a >> b;
		G[--a].push_back(make_pair(--b,i));
		G[b].push_back(make_pair(a,i));}

	int a =0, b =M;
	while(b-a > 1) {
		int c =(b+a)/2;
		if(bipar(c)) a =c;
		else b =c;}
	cout << b << "\n";
	return 0;}

// look at my code
// my code is amazing
