#include <bits/stdc++.h>
using namespace std;
template <class T>
using vv = vector<vector<T>>;
template <class T>
ostream &operator<<(ostream &os, const vector<T> &t) {
  os << "{";
  for (int(i) = 0; (i) < (t.size()); ++(i)) {
    os << t[i] << ",";
  }
  os << "}" << endl;
  return os;
}
template <class S, class T>
ostream &operator<<(ostream &os, const pair<S, T> &t) {
  return os << "(" << t.first << "," << t.second << ")";
}
template <class T>
inline bool MX(T &l, const T &r) {
  return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
  return l > r ? l = r, 1 : 0;
}
const long long MOD = 1e9 + 7;
int d[3123][3123];
void upd(vector<pair<int, int>> re[3], pair<int, int> d, int t) {
  if (d.first >= MOD) return;
  if (d >= re[0][t]) {
    re[2][t] = re[1][t];
    re[1][t] = re[0][t];
    re[0][t] = d;
  } else if (d >= re[1][t]) {
    re[2][t] = re[1][t];
    re[1][t] = d;
  } else if (d > re[2][t]) {
    re[2][t] = d;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(0);
  int n, m;
  cin >> n >> m;
  vv<int> g(n);
  int x, y;
  for (int(i) = 0; (i) < (m); ++(i)) {
    cin >> x >> y;
    --x;
    --y;
    g[x].push_back(y);
  }
  fill(d[0], d[0] + 3123 * 3123, MOD);
  for (int(s) = 0; (s) < (n); ++(s)) {
    queue<int> que;
    que.emplace(s);
    d[s][s] = 0;
    while (que.size()) {
      int x = que.front();
      que.pop();
      for (int y : g[x])
        if (MN(d[s][y], d[s][x] + 1)) que.emplace(y);
    }
  }
  vector<pair<int, int>> din[3], dout[3];
  for (int(i) = 0; (i) < (3); ++(i)) {
    din[i].resize(n);
    dout[i].resize(n);
  }
  for (int(i) = 0; (i) < (n); ++(i))
    for (int(j) = 0; (j) < (n); ++(j))
      if (i != j) {
        upd(din, pair<int, int>(d[j][i], j), i);
        upd(dout, pair<int, int>(d[i][j], j), i);
      }
  long long re = -1;
  vector<int> rev;
  for (int(i) = 0; (i) < (n); ++(i))
    for (int(j) = 0; (j) < (n); ++(j))
      if (i != j && d[i][j] < MOD) {
        for (int(a) = 0; (a) < (3); ++(a))
          for (int(b) = 0; (b) < (3); ++(b)) {
            const pair<int, int> p = din[a][i], q = dout[b][j];
            if (p.first == 0 || q.first == 0) continue;
            if (p.second == j || p.second == q.second || q.second == i)
              continue;
            if (MX(re, d[i][j] + p.first + q.first + 0ll)) {
              rev = {p.second, i, j, q.second};
            }
          }
      }
  for (int(i) = 0; (i) < (4); ++(i)) {
    if (i) cout << " ";
    cout << rev[i] + 1;
  }
  cout << endl;
  return 0;
}
