#include <bits/stdc++.h>
#define F first
#define S second
#define forn(i, n) for(int i = 0; i < int(n); i++)
#define p_b push_back
#define all(c) c.begin(), c.end()
using namespace std;
typedef long long ll; //printf("%lld ", ll); to out put long
typedef pair <int , int> pii;
typedef pair <ll , ll> pll;
const double eps = 1e-6;
const int MAXN = 1e5 + 5;
const ll MOD = 1e9 + 7;
bool ODD(ll O) {return (O % 2 != 0);}
ll gcd(ll a, ll b) {return __gcd(a , b);}
ll lcm(ll a, ll b) {return a * b / gcd(a , b);}
int dx[] = {1, 0, -1 ,0 , -1 , 0};
int dy[] = {0, 1, 0, -1 , -1 , 0};
ll power (ll x, ll y) {
if(y == 0) return 1;
if(ODD(y)) return (x * power(x , y / 2) * power(x , y / 2));
return (power(x , y / 2) * power(x , y / 2));
}
/*------ never give up --------*/
vector < vector <int> > adj;
vector <bool> vis, in_stack;
stack <int> st;
map <pii , bool> mp;
vector <pair <pii , int> > vc;
int rm = 0;
void dfs(int node) {
if(rm <= 0) return;
if(vis[node]) {
if(in_stack[node]) {
int x1 = -1, x2 = -1, x3 = st.top();
while(x1 != node) {
x1 = st.top();
st.pop();
if(st.empty()) break;
if(st.top() == node) {
x2 = st.top();
mp[{x2 , x1}] = 1;
--rm;
if(rm <= 0) return;
break;
}
x2 = st.top();
mp[{x2 , x1}] = 1;
in_stack[x1] = 0;
--rm;
if(rm <= 0) return;
}
mp[{node , x3}] = 1;
in_stack[node] = 1;
} else return;
}
vis[node] = in_stack[node] = 1;
st.push(node);
for(int ch : adj[node]) {
if(mp[{node , ch}]) continue;
dfs(ch);
}
}
void solve(int n , int k , int m) {
vis.resize(n + 5 , 0);
in_stack.resize(n + 5 , 0);
rm = k - m;
dfs(0);
cout << n << "\n";
for(int i = 0; i < m && k > 0; i++) {
if(!mp[{vc[i].first.F , vc[i].first.S}]) {
cout << vc[i].second + 1 << "\n";
--k;
}
}
}
int main () {
int t = 1;
//scanf("%d", &t);
int n, m, k;
while(t--) {
cin >> n >> m >> k;
adj.resize(n + 5);
for(int i = 0; i < m; i++) {
int u, v;
cin >> u >> v;
u--, v--;
adj[u].push_back(v);
vc.push_back({{u , v} , i});
}
solve(n , k , m);
}
return 0;
}
CiNpbmNsdWRlIDxiaXRzL3N0ZGMrKy5oPgojZGVmaW5lIEYgZmlyc3QKI2RlZmluZSBTIHNlY29uZAojZGVmaW5lIGZvcm4oaSwgbikgZm9yKGludCBpID0gMDsgaSA8IGludChuKTsgaSsrKQojZGVmaW5lIHBfYiBwdXNoX2JhY2sKI2RlZmluZSBhbGwoYykgICAgICAgICAgICAgIGMuYmVnaW4oKSwgYy5lbmQoKQp1c2luZyBuYW1lc3BhY2Ugc3RkOwp0eXBlZGVmIGxvbmcgbG9uZyBsbDsgLy9wcmludGYoIiVsbGQgIiwgbGwpOyB0byBvdXQgcHV0IGxvbmcKdHlwZWRlZiBwYWlyIDxpbnQgLCBpbnQ+IHBpaTsKdHlwZWRlZiBwYWlyIDxsbCAsIGxsPiBwbGw7CmNvbnN0IGRvdWJsZSBlcHMgPSAxZS02Owpjb25zdCBpbnQgTUFYTiA9IDFlNSArIDU7CmNvbnN0IGxsIE1PRCA9IDFlOSArIDc7CmJvb2wgT0REKGxsIE8pIHtyZXR1cm4gKE8gJSAyICE9IDApO30KbGwgZ2NkKGxsIGEsIGxsIGIpIHtyZXR1cm4gX19nY2QoYSAsIGIpO30KbGwgbGNtKGxsIGEsIGxsIGIpIHtyZXR1cm4gYSAqIGIgLyBnY2QoYSAsIGIpO30KaW50IGR4W10gPSB7MSwgMCwgLTEgLDAgLCAtMSAsIDB9OwppbnQgZHlbXSA9IHswLCAxLCAwLCAtMSAsIC0xICwgMH07CmxsIHBvd2VyIChsbCB4LCBsbCB5KSB7CiAgICBpZih5ID09IDApIHJldHVybiAxOwogICAgaWYoT0REKHkpKSByZXR1cm4gKHggKiBwb3dlcih4ICwgeSAvIDIpICogcG93ZXIoeCAsIHkgLyAyKSk7CiAgICByZXR1cm4gKHBvd2VyKHggLCB5IC8gMikgKiBwb3dlcih4ICwgeSAvIDIpKTsKfQovKi0tLS0tLSBuZXZlciBnaXZlIHVwIC0tLS0tLS0tKi8KCnZlY3RvciA8IHZlY3RvciA8aW50PiAgPiBhZGo7CnZlY3RvciA8Ym9vbD4gdmlzLCBpbl9zdGFjazsKc3RhY2sgPGludD4gc3Q7Cm1hcCA8cGlpICwgYm9vbD4gbXA7CnZlY3RvciA8cGFpciA8cGlpICwgaW50PiA+IHZjOwppbnQgcm0gPSAwOwp2b2lkIGRmcyhpbnQgbm9kZSkgewogICAgaWYocm0gPD0gMCkgcmV0dXJuOwogICAgaWYodmlzW25vZGVdKSB7CiAgICAgICAgaWYoaW5fc3RhY2tbbm9kZV0pIHsKICAgICAgICAgICAgaW50IHgxID0gLTEsIHgyID0gLTEsIHgzID0gc3QudG9wKCk7CiAgICAgICAgICAgIHdoaWxlKHgxICE9IG5vZGUpIHsKICAgICAgICAgICAgICAgIHgxID0gc3QudG9wKCk7CiAgICAgICAgICAgICAgICBzdC5wb3AoKTsKICAgICAgICAgICAgICAgIGlmKHN0LmVtcHR5KCkpIGJyZWFrOwogICAgICAgICAgICAgICAgaWYoc3QudG9wKCkgPT0gbm9kZSkgewogICAgICAgICAgICAgICAgICAgIHgyID0gc3QudG9wKCk7CiAgICAgICAgICAgICAgICAgICAgbXBbe3gyICwgeDF9XSA9IDE7CiAgICAgICAgICAgICAgICAgICAgLS1ybTsKICAgICAgICAgICAgICAgICAgICBpZihybSA8PSAwKSByZXR1cm47CiAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICB4MiA9IHN0LnRvcCgpOwogICAgICAgICAgICAgICAgbXBbe3gyICwgeDF9XSA9IDE7CiAgICAgICAgICAgICAgICBpbl9zdGFja1t4MV0gPSAwOwogICAgICAgICAgICAgICAgLS1ybTsKICAgICAgICAgICAgICAgIGlmKHJtIDw9IDApIHJldHVybjsKICAgICAgICAgICAgfQogICAgICAgICAgICBtcFt7bm9kZSAsIHgzfV0gPSAxOwogICAgICAgICAgICBpbl9zdGFja1tub2RlXSA9IDE7CgoKICAgICAgICB9IGVsc2UgcmV0dXJuOwogICAgfQogICAgdmlzW25vZGVdID0gaW5fc3RhY2tbbm9kZV0gPSAxOwogICAgc3QucHVzaChub2RlKTsKICAgIGZvcihpbnQgY2ggOiBhZGpbbm9kZV0pIHsKICAgICAgICBpZihtcFt7bm9kZSAsIGNofV0pIGNvbnRpbnVlOwogICAgICAgIGRmcyhjaCk7CiAgICB9Cn0Kdm9pZCBzb2x2ZShpbnQgbiAsIGludCBrICwgaW50IG0pIHsKICAgIHZpcy5yZXNpemUobiArIDUgLCAwKTsKICAgIGluX3N0YWNrLnJlc2l6ZShuICsgNSAsIDApOwogICAgcm0gPSBrIC0gbTsKICAgIGRmcygwKTsKICAgIGNvdXQgPDwgbiA8PCAiXG4iOwogICAgZm9yKGludCBpID0gMDsgaSA8IG0gJiYgayA+IDA7IGkrKykgewogICAgICAgIGlmKCFtcFt7dmNbaV0uZmlyc3QuRiAsIHZjW2ldLmZpcnN0LlN9XSkgewogICAgICAgICAgICBjb3V0IDw8IHZjW2ldLnNlY29uZCArIDEgPDwgIlxuIjsKICAgICAgICAgICAgLS1rOwogICAgICAgIH0KICAgIH0KfQppbnQgbWFpbiAoKSB7CiAgICBpbnQgdCA9IDE7CiAgICAvL3NjYW5mKCIlZCIsICZ0KTsKICAgIGludCBuLCBtLCBrOwogICAgd2hpbGUodC0tKSB7CiAgICAgICAgY2luID4+IG4gPj4gbSA+PiBrOwogICAgICAgIGFkai5yZXNpemUobiArIDUpOwogICAgICAgIGZvcihpbnQgaSA9IDA7IGkgPCBtOyBpKyspIHsKICAgICAgICAgICAgaW50IHUsIHY7CiAgICAgICAgICAgIGNpbiA+PiB1ID4+IHY7CiAgICAgICAgICAgIHUtLSwgdi0tOwogICAgICAgICAgICBhZGpbdV0ucHVzaF9iYWNrKHYpOwogICAgICAgICAgICB2Yy5wdXNoX2JhY2soe3t1ICwgdn0gLCBpfSk7CiAgICAgICAgfQogICAgICAgIHNvbHZlKG4gLCBrICwgbSk7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0K