#include <bits/stdc++.h>
using namespace std;
vector<int> e[3005];
int a, b, step[3005][3005], N, M, p[5], res = -1, ans[5], q[3005], qe,
                                        st[3005][5], ed[3005][5];
inline void bfs(int x) {
  step[x][x] = 0;
  qe = 0;
  q[qe++] = x;
  for (int i = 0; i < qe; i++) {
    int ff = q[i];
    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[qe++] = *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 = 0; j < 5; j++) st[i][j] = ed[i][j] = i;
    for (int j = 1; j <= N; j++) {
      if (j == i) continue;
      for (int k = 3; k > -1; k--) {
        if (step[i][st[i][k]] < step[i][j])
          st[i][k + 1] = st[i][k], st[i][k] = j;
        if (step[ed[i][k]][i] < step[j][i])
          ed[i][k + 1] = ed[i][k], ed[i][k] = j;
      }
    }
  }
  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 < 4; u++)
          for (int k = 0; k < 4; k++) {
            p[1] = ed[i][u], p[2] = i, p[3] = j, p[4] = st[j][k];
            upDate();
          }
  for (int i = 1; i <= 4; i++) cout << ans[i] << " ";
  return 0;
}
