#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T qmin(const T a, const T b) {
  return a < b ? a : b;
}
template <typename T>
inline T qmax(const T a, const T b) {
  return a > b ? a : b;
}
template <typename T>
inline void getmin(T &a, const T b) {
  if (a > b) a = b;
}
template <typename T>
inline void getmax(T &a, const T b) {
  if (a < b) a = b;
}
inline void fileio(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
const int inf = 1e9 + 7;
const long long linf = 1e17 + 7;
const int N = 4e3 + 7, M = 1e5 + 7;
int v[M], nxt[M], head[N];
int dist[N][N], mxto[N][3], mxfrom[N][3];
int n, m;
int q[N], st, ed;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    static int x, y;
    scanf("%d%d", &x, &y);
    v[i] = y, nxt[i] = head[x], head[x] = i;
  }
  for (int i = 1; i <= n; ++i) {
    st = 0, ed = 1, q[ed] = i;
    while (st != ed) {
      int u = q[++st];
      for (int e = head[u]; e; e = nxt[e]) {
        if (v[e] == i || dist[i][v[e]]) continue;
        dist[i][v[e]] = dist[i][u] + 1;
        q[++ed] = v[e];
      }
    }
    for (int j = 1; j <= n; ++j) {
      for (int k = 0; k < 3; ++k) {
        if (dist[i][j] > dist[mxto[j][k]][j]) {
          for (int l = 2; l > k; --l) mxto[j][l] = mxto[j][l - 1];
          mxto[j][k] = i;
          break;
        }
      }
      for (int k = 0; k < 3; ++k) {
        if (dist[i][j] > dist[i][mxfrom[i][k]]) {
          for (int l = 2; l > k; --l) mxfrom[i][l] = mxfrom[i][l - 1];
          mxfrom[i][k] = j;
          break;
        }
      }
    }
  }
  int ans = 0, ap, aq, ar, as;
  for (int p = 1, q, r, s, tot; p <= n; ++p) {
    for (q = 1; q <= n; ++q) {
      if (!dist[p][q]) continue;
      for (int i1 = 0; i1 < 2; ++i1) {
        if (!mxto[p][i1] || mxto[p][i1] == q) continue;
        for (int i2 = 0; i2 < 2; ++i2) {
          if (!mxfrom[q][i2] || mxfrom[q][i2] == mxto[p][i1] ||
              mxfrom[q][i2] == p)
            continue;
          r = mxto[p][i1], s = mxfrom[q][i2],
          tot = dist[r][p] + dist[p][q] + dist[q][s];
          if (tot > ans) ans = tot, ap = r, aq = p, ar = q, as = s;
          break;
        }
      }
    }
  }
  printf("%d %d %d %d\n", ap, aq, ar, as);
  return 0;
}
