#include <bits/stdc++.h>
using namespace std;

using ll=int64_t;
#define int ll

#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(),x.end()
#ifdef LOCAL
#define cerr (cerr<<"-- line "<<__LINE__<<" -- ")
#else
class CerrDummy{}cerrDummy;
template<class T>
CerrDummy& operator<<(CerrDummy&cd,const T&){
	return cd;
}
using charTDummy=char;
using traitsDummy=char_traits<charTDummy>;
CerrDummy& operator<<(CerrDummy&cd,basic_ostream<charTDummy,traitsDummy>&(basic_ostream<charTDummy,traitsDummy>&)){
	return cd;
}
#define cerr cerrDummy
#endif
#define REACH cerr<<"reached"<<endl
#define DMP(x) cerr<<#x<<":"<<x<<endl
#define ZERO(x) memset(x,0,sizeof(x))
#define ONE(x) memset(x,-1,sizeof(x))

using pi=pair<int,int>;
using vi=vector<int>;
using ld=long double;

template<class T,class U>
ostream& operator<<(ostream& os,const pair<T,U>& p){
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator <<(ostream& os,const vector<T>& v){
	os<<"{";
	REP(i,(int)v.size()){
		if(i)os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

ll read(){
	ll i;
	scanf("%"  SCNd64,&i);
	return i;
}

void printSpace(){
	printf(" ");
}

void printEoln(){
	printf("\n");
}

void print(ll x,int suc=1){
	printf("%" PRId64,x);
	if(suc==1)
		printEoln();
	if(suc==2)
		printSpace();
}

string readString(){
	static char buf[3341000];
	scanf("%s",buf);
	return string(buf);
}

char* readCharArray(){
	static char buf[3341000];
	static int bufUsed=0;
	char* ret=buf+bufUsed;
	scanf("%s",ret);
	bufUsed+=strlen(ret)+1;
	return ret;
}

template<class T,class U>
void chmax(T& a,U b){
	if(a<b)
		a=b;
}

template<class T,class U>
void chmin(T& a,U b){
	if(b<a)
		a=b;
}

template<class T>
T Sq(const T& t){
	return t*t;
}

#define CAPITAL
void Yes(bool ex=true){
	#ifdef CAPITAL
	cout<<"YES"<<endl;
	#else
	cout<<"Yes"<<endl;
	#endif
	if(ex)exit(0);
}
void No(bool ex=true){
	#ifdef CAPITAL
	cout<<"NO"<<endl;
	#else
	cout<<"No"<<endl;
	#endif
	if(ex)exit(0);
}

const ll infLL=LLONG_MAX/3;

#ifdef int
const int inf=infLL;
#else
const int inf=INT_MAX/2-100;
#endif

struct UnionFind{
	vi par;
	UnionFind(int n){
		par.resize(n,-1);
	}
	int Find(int a){
		return par[a]==-1?a:(par[a]=Find(par[a]));
	}
	void Unite(int a,int b){
		assert(par[a]==-1);
		assert(par[b]==-1);
		par[b]=a;
	}
};

//Union-Find without Rank
const int Nmax=100010;
struct Edge{
	int to,cost,from;
	bool operator>(const Edge&e)const{
		return cost>e.cost;
	}
};
vector<Edge> g[Nmax];

struct EQ{
	using pqpi=priority_queue<Edge,vector<Edge>,greater<Edge>>;
	pqpi* q;
	int off;
	void Init(const vector<Edge>&es){
		q=new pqpi();
		for(auto e:es)
			q->push(e);
		off=0;
	}
	void Merge(EQ& x){
		if(q->size()<x.q->size())
			swap(*this,x);
		while(!x.Empty()){
			auto e=x.Pop();
			q->push(Edge{e.to,e.cost-off,e.from});
		}
	}
	bool Empty(){
		return q->empty();
	}
	Edge Pop(){
		auto e=q->top();
		q->pop();
		return Edge{e.to,e.cost+off,e.from};
	}
	void Del(){
		delete q;
	}
};
//leaf->root
auto solve(int n,int root){
	vector<EQ> eqs(n);
	REP(i,n)
		eqs[i].Init(g[i]);
	vi state(n,0);
	state[root]=2;
	vi curCost(n);
	
	UnionFind uf(n);
	int ans=0;
	vi idx;
	REP(i,n)if(!state[i]){
		vi vs{i};
		state[i]=1;
		while(1){
			Edge e=eqs[vs.back()].Pop();
			curCost[vs.back()]=e.cost;
			ans+=e.cost;
			int to=uf.Find(e.to);
			if(state[to]==0){
				vs.PB(to);
				state[to]=1;
			}else if(state[to]==1){
				int r=vs.size(),l=r-1;
				while(vs[l]!=to)
					l--;
				FOR(j,l,r){
					eqs[vs[j]].off-=curCost[vs[j]];
					if(l<j){
						eqs[vs[l]].Merge(eqs[vs[j]]);
						uf.Unite(vs[l],vs[j]);
					}
				}
				vs.resize(l+1);
			}else{
				int tmp=e.cost;
				while(1){
					if(tmp==e.cost)
						idx.PB(e.from);
					if(eqs[vs.back()].Empty())
						break;
					e=eqs[vs.back()].Pop();
				}
				break;
			}
		}
		for(auto v:vs)
			state[v]=2;
	}
	
	REP(i,n)
		eqs[i].Del();
	
	return make_tuple(ans,idx);
}

signed main(){
	int n=read(),m=read();
	REP(_,m){
		int a=read(),b=read();
		g[b].PB(Edge{a,0,b});
		g[a].PB(Edge{b,1,a});
	}
	REP(i,n)
		g[i].PB(Edge{n,inf,i});
	int minCost;
	vi idx;
	tie(minCost,idx)=solve(n+1,n);
	minCost-=inf;
	sort(ALL(idx));
	print(idx.size(),2);
	print(minCost);
	REP(i,idx.size()){
		print(idx[i],i==int(idx.size())-1?1:2);
	}
}



Measured memory_bytes: 23064