#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3000 + 10, MAXM = 5000 + 10;
int n, m, dis[MAXN][MAXN], rdis[MAXN][MAXN], mx, ans[5];
vector<vector<int> > E, rE;
int mxval[2][MAXN], rmxval[2][MAXN], cnt[MAXN], rcnt[MAXN];
void bfs(const vector<vector<int> >& E, int dis[MAXN][MAXN], int mxval[2][MAXN],
         int cnt[MAXN]) {
  for (int S = (0), Send = (n); S < Send; ++S) {
    queue<int> q;
    q.push(S);
    dis[S][S] = 0;
    while (!q.empty()) {
      int u = q.front();
      q.pop();
      for (int v : E[u])
        if (dis[S][v] > dis[S][u] + 1) {
          dis[S][v] = dis[S][u] + 1;
          q.push(v);
        }
    }
    mxval[0][S] = mxval[1][S] = S;
    for (int i = (0), iend = (n); i < iend; ++i)
      if (dis[S][i] <= 1e9 && i != S) {
        if (dis[S][i] > dis[S][mxval[1][S]]) {
          mxval[0][S] = mxval[1][S];
          mxval[1][S] = i;
        } else if (dis[S][i] > dis[S][mxval[0][S]]) {
          mxval[0][S] = i;
        }
      }
    if (mxval[1][S] != S) cnt[S]++;
    if (mxval[0][S] != S) cnt[S]++;
  }
}
void upd(int x, int u, int v, int y) {
  if (mx < (dis[u][v] + dis[x][u] + rdis[y][v])) {
    mx = dis[u][v] + dis[x][u] + rdis[y][v];
    ans[0] = x, ans[1] = u, ans[2] = v, ans[3] = y;
  }
}
void work(int x, int u, int v, int y) {
  if (x == y) {
    if (rcnt[u] >= 2 && x != rmxval[0][u]) work(rmxval[0][u], u, v, y);
    if (cnt[v] >= 2 && y != mxval[0][v]) work(x, u, v, mxval[0][v]);
  } else if (x == v) {
    if (rcnt[u] >= 2 && x != rmxval[0][u]) work(rmxval[0][u], u, v, y);
  } else if (u == y) {
    if (cnt[v] >= 2 && y != mxval[0][v]) work(x, u, v, mxval[0][v]);
  } else
    upd(x, u, v, y);
}
void get(int u, int v) {
  if (dis[u][v] < 1e9 && u != v && cnt[v] && rcnt[u]) {
    int x = rmxval[1][u], y = mxval[1][v];
    work(x, u, v, y);
  }
}
int main() {
  scanf("%d %d", &n, &m);
  E.resize(n), rE.resize(n);
  for (int _ = (0), _end = (m); _ < _end; ++_) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--, v--;
    E[u].push_back(v), rE[v].push_back(u);
  }
  memset(dis, 0x3f, sizeof dis), memset(rdis, 0x3f, sizeof rdis);
  bfs(E, dis, mxval, cnt), bfs(rE, rdis, rmxval, rcnt);
  for (int u = (0), uend = (n); u < uend; ++u)
    for (int v = (0), vend = (n); v < vend; ++v) get(u, v);
  for (int i = (0), iend = (4); i < iend; ++i) printf("%d ", ans[i] + 1);
  return 0;
}
