#include <bits/stdc++.h>
using namespace std;
vector<int> nei[3007];
int n, m;
int dist[3007][3007];
int mxfrm[3007][3], mxto[3007][3];
void bfs(int start) {
  memset((void*)dist[start], -1, sizeof(dist[start]));
  queue<int> q, bs;
  q.push(start);
  bs.push(0);
  dist[start][start] = 0;
  while (!q.empty()) {
    int qq = q.front(), bb = bs.front();
    q.pop();
    bs.pop();
    for (int i : nei[qq])
      if (dist[start][i] == -1) {
        q.push(i);
        bs.push(bb + 1);
        dist[start][i] = bb + 1;
      }
  }
}
void gengxin(int a, int b) {
  if (dist[a][b] > dist[a][mxfrm[a][0]]) {
    mxfrm[a][2] = mxfrm[a][1];
    mxfrm[a][1] = mxfrm[a][0];
    mxfrm[a][0] = b;
  } else if (dist[a][b] > dist[a][mxfrm[a][1]]) {
    mxfrm[a][2] = mxfrm[a][1];
    mxfrm[a][1] = b;
  } else if (dist[a][b] > dist[a][mxfrm[a][2]]) {
    mxfrm[a][2] = b;
  }
  if (dist[a][b] > dist[mxto[b][0]][b]) {
    mxto[b][2] = mxto[b][1];
    mxto[b][1] = mxto[b][0];
    mxto[b][0] = a;
  } else if (dist[a][b] > dist[mxto[b][1]][b]) {
    mxto[b][2] = mxto[b][1];
    mxto[b][1] = a;
  } else if (dist[a][b] > dist[mxto[b][2]][b]) {
    mxto[b][2] = a;
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    nei[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) gengxin(i, j);
  int maxsum = 0, maxa, maxb, maxc, maxd;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i != j && dist[i][j] != -1)
        for (int k = 0; k < 3; k++)
          for (int l = 0; l < 3; l++) {
            int ii = mxto[i][k], jj = mxfrm[j][l];
            if (ii != 0 && jj != 0 && ii != jj && i != jj && j != ii &&
                i != ii && j != jj && dist[ii][i] != -1 && dist[j][jj] != -1 &&
                dist[ii][i] + dist[i][j] + dist[j][jj] > maxsum) {
              maxsum = dist[ii][i] + dist[i][j] + dist[j][jj];
              maxa = ii;
              maxb = i;
              maxc = j;
              maxd = jj;
            }
          }
  printf("%d %d %d %d\n", maxa, maxb, maxc, maxd);
  return 0;
}
