// 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
Ly8gaW9zdHJlYW0gaXMgdG9vIG1haW5zdHJlYW0KI2luY2x1ZGUgPGNzdGRpbz4KLy8gYml0Y2ggcGxlYXNlCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHN0cmluZz4KI2luY2x1ZGUgPHF1ZXVlPgojaW5jbHVkZSA8c3RhY2s+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNpbmNsdWRlIDxjbWF0aD4K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