#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = (int)5e3 + 42;
int n, m;
vector<int> G[MAXN];
int has[MAXN][MAXN];
void read()
{
cin >> n >> m;
for(int i = 0; i < m; i++)
{
int u, v;
cin >> u >> v;
G[u].push_back(v);
G[v].push_back(u);
}
}
/*
int dist[MAXN];
int par[MAXN];
void dfs(int u)
{
int sz = G[u].size(), v;
for(int i = 0; i < sz; i++)
{
v = G[u][i];
if(dist[v] == -1)
{
dist[v] = dist[u] + 1;
par[v] = u;
dfs(v);
}
else if(dist[v] == dist[u] - 3)
{
int ver = u;
cout << "TAIP" << endl;
for(int k = 0; k < 4; k++, ver = par[ver])
cout << ver << " ";
cout << endl;
exit(0);
}
}
}
*/
void solve()
{
memset(has, -1, sizeof(has));
//dist[1] = 0;
//dfs(1);
for(int ver = 1; ver <= n; ver++)
{
for(int j = 0; j < G[ver].size(); j++)
for(int i = j + 1; i < G[ver].size(); i++)
{
int v = G[ver][j], u = G[ver][i];
if(has[v][u] != -1 || has[u][v] != -1)
{
cout << "TAIP" << endl;
cout << u << " " << ver << " " << v << " " << has[u][v] << endl;
return;
}
has[u][v] = ver;
has[v][u] = ver;
}
}
cout << "NE" << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
read();
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgZW5kbCAnXG4nCgp1c2luZyBuYW1lc3BhY2Ugc3RkOwpjb25zdCBpbnQgTUFYTiA9IChpbnQpNWUzICsgNDI7CgppbnQgbiwgbTsKdmVjdG9yPGludD4gR1tNQVhOXTsKaW50IGhhc1tNQVhOXVtNQVhOXTsKCnZvaWQgcmVhZCgpCnsKCWNpbiA+PiBuID4+IG07CgoJZm9yKGludCBpID0gMDsgaSA8IG07IGkrKykKCXsKCQlpbnQgdSwgdjsKCQljaW4gPj4gdSA+PiB2OwoJCUdbdV0ucHVzaF9iYWNrKHYpOwoJCUdbdl0ucHVzaF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