#include <bits/stdc++.h>
using namespace std;
int step[3005][3005], N, M, a, b, res = -1, p[5], ans[5];
vector<int> e[3005];
vector<pair<int, int> > st[3005], fin[3005];
inline void bfs(int x) {
  queue<int> q;
  step[x][x] = 0;
  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);
      }
  }
}
void upDate() {
  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 = 1; i < 4; i++) l += step[p[i]][p[i + 1]];
  if (l > res) {
    res = l;
    for (int i = 1; i <= 4; i++) ans[i] = p[i];
  }
}
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);
  for (int i = 1; i <= N; i++) {
    for (int j = 1; j <= N; j++) {
      if (step[i][j] > 0) st[i].push_back(make_pair(step[i][j], j));
      if (st[i].size() > 3) {
        sort(st[i].begin(), st[i].end());
        st[i].erase(st[i].begin());
      }
      if (step[j][i] > 0) fin[i].push_back(make_pair(step[j][i], j));
      if (fin[i].size() > 3) {
        sort(fin[i].begin(), fin[i].end());
        fin[i].erase(fin[i].begin());
      }
    }
  }
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (i != j && step[i][j] != -1) {
        p[2] = i, p[3] = j;
        for (vector<pair<int, int> >::iterator t = fin[i].begin();
             t != fin[i].end(); t++)
          for (vector<pair<int, int> >::iterator k = st[j].begin();
               k != st[j].end(); k++) {
            pair<int, int> f = *t, h = *k;
            p[1] = f.second, p[4] = h.second;
            upDate();
          }
      }
  for (int i = 1; i <= 4; i++) cout << ans[i] << " ";
  return 0;
}
