#include <bits/stdc++.h>
using namespace std;
const int N = 6010;
vector<int> V[N];
int n, m, dst[N][N], ans[4];
vector<pair<pair<int, int>, int> > edges;
void bfs() {
  for (int i = 1; i <= n; ++i) {
    dst[i][i] = 0;
    queue<vector<int> > q;
    q.push(V[i]);
    while (!q.empty()) {
      vector<int> tmp = q.front();
      q.pop();
      for (int j = 1; j < tmp.size(); ++j)
        if (dst[i][tmp[j]] == 1000000006) {
          dst[i][tmp[j]] = dst[i][tmp[0]] + 1;
          q.push(V[tmp[j]]);
        }
    }
  }
}
int nxt[N][5], nxtd[N][5];
int pre[N][5], pred[N][5];
void choose(int c) {
  for (int i = 1; i <= n; ++i)
    if (i != c && dst[c][i] != 1000000006) {
      nxt[c][4] = i;
      nxtd[c][4] = dst[c][i];
      for (int j = 4; j >= 1; --j)
        if (nxtd[c][j] > nxtd[c][j - 1]) {
          swap(nxtd[c][j], nxtd[c][j - 1]);
          swap(nxt[c][j], nxt[c][j - 1]);
        }
    }
  for (int i = 1; i <= n; ++i)
    if (i != c && dst[i][c] != 1000000006) {
      pre[c][4] = i;
      pred[c][4] = dst[i][c];
      for (int j = 4; j >= 1; --j)
        if (pred[c][j] > pred[c][j - 1]) {
          swap(pred[c][j], pred[c][j - 1]);
          swap(pre[c][j], pre[c][j - 1]);
        }
    }
}
int total = 0;
void cal(pair<pair<int, int>, int> t) {
  for (int i = 0; i < 4; ++i) {
    if (pre[t.first.first][i] == 0) continue;
    for (int j = 0; j < 4; ++j) {
      if (nxt[t.first.second][j] == 0) continue;
      if (pre[t.first.first][i] == t.first.second) continue;
      if (nxt[t.first.second][j] == t.first.first) continue;
      if (pre[t.first.first][i] == nxt[t.first.second][j]) continue;
      if (pred[t.first.first][i] + t.second + nxtd[t.first.second][j] > total) {
        total = pred[t.first.first][i] + t.second + nxtd[t.first.second][j];
        ans[0] = pre[t.first.first][i];
        ans[1] = t.first.first;
        ans[2] = t.first.second;
        ans[3] = nxt[t.first.second][j];
      }
    }
  }
}
int main() {
  int u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; ++i) V[i].push_back(i);
  for (int i = 0; i < m; ++i) {
    cin >> u >> v;
    if (u != v) V[u].push_back(v);
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) dst[i][j] = 1000000006;
  bfs();
  for (int i = 1; i <= n; ++i) choose(i);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (dst[i][j] != 1000000006 && dst[i][j] != 0)
        edges.push_back(make_pair(make_pair(i, j), dst[i][j]));
  for (int i = 0; i < edges.size(); ++i) cal(edges[i]);
  for (int i = 0; i < 4; ++i) cout << ans[i] << " ";
  cout << endl;
}
