#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > F[3005], Z[3005];
vector<int> e[3005], first[3005];
int a, b, N, M, p[5], res = -1, ans[5], step[3005][3005];
inline void init1(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);
      }
  }
  vector<pair<int, int> > res;
  for (int i = 1; i <= N; i++) {
    if (step[x][i] > 0) res.push_back(make_pair(step[x][i], i));
    sort(res.rbegin(), res.rend());
    if (res.size() == 4) res.erase(res.end());
  }
  Z[x] = res;
}
inline void init2(int x) {
  int fu[3005];
  memset(fu, -1, sizeof(fu));
  fu[x] = 0;
  queue<int> q;
  q.push(x);
  while (!q.empty()) {
    int ff = q.front();
    q.pop();
    for (vector<int>::iterator it = first[ff].begin(); it != first[ff].end();
         it++)
      if (fu[*it] == -1) {
        fu[*it] = fu[ff] + 1;
        q.push(*it);
      }
  }
  vector<pair<int, int> > res;
  for (int i = 1; i <= N; i++) {
    if (fu[i] > 0) res.push_back(make_pair(fu[i], i));
    sort(res.rbegin(), res.rend());
    if (res.size() == 4) res.erase(res.end());
  }
  F[x] = res;
}
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), first[b].push_back(a);
  }
  for (int i = 1; i <= N; i++) init1(i), init2(i);
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      if (i != j && step[i][j] > 0)
        for (int u = 0; u < F[i].size(); u++)
          for (int k = 0; k < Z[j].size(); k++) {
            p[1] = F[i][u].second;
            p[2] = i;
            p[3] = j;
            p[4] = Z[j][k].second;
            upDate();
          }
  for (int i = 1; i <= 4; i++) cout << ans[i] << " ";
  return 0;
}
