#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > from[3005], to[3005];
vector<int> e[3005];
int a, b, step[3005][3005], N, M, p[5], res = -1, ans[5];
inline void bfs(int x) {
  step[x][x] = 0;
  queue<int> q;
  q.push(x);
  while (!q.empty()) {
    int ff = q.front();
    q.pop();
    for (vector<int>::iterator it = e[ff].begin(); it != e[ff].end(); it++)
      if (step[x][*it] == -1) {
        step[x][*it] = step[x][ff] + 1;
        q.push(*it);
      }
  }
}
inline void init() {
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (step[i][j] > 0) from[i].insert(make_pair(step[i][j], j));
      while (from[i].size() > 4) from[i].erase(from[i].begin());
    }
    for (int j = 1; j <= N; j++) {
      if (step[j][i] > 0) to[i].insert(make_pair(step[j][i], j));
      while (to[i].size() > 4) to[i].erase(to[i].begin());
    }
  }
}
inline void change() {
  for (int i = 1; i <= 4; i++)
    for (int j = 1; j <= 4; j++)
      if (i != j && p[i] == p[j]) return;
  int l = 0;
  for (int i = 2; i <= 4; i++) l += step[p[i - 1]][p[i]];
  if (l > res)
    for (int i = 1; i <= 4; i++) ans[i] = p[i], res = l;
}
int main() {
  memset(step, -1, sizeof(step));
  cin >> N >> M;
  while (M--) {
    cin >> a >> b;
    if (a != b) e[a].push_back(b);
  }
  for (int i = 1; i <= N; i++) bfs(i);
  init();
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (i != j && step[i][j] > 0)
        for (set<pair<int, int> >::iterator t = to[i].begin(); t != to[i].end();
             t++)
          for (set<pair<int, int> >::iterator k = from[j].begin();
               k != from[j].end(); k++) {
            pair<int, int> tt = *t, kk = *k;
            p[1] = tt.second, p[2] = i, p[3] = j, p[4] = kk.second;
            change();
          }
  for (int i = 1; i <= 4; i++) cout << ans[i] << " ";
  return 0;
}
