#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
const int oo = 1e9;
vector<int> g[N], gt[N];
vector<pair<int, int> > b[N], bt[N];
int cost[N][N];
void bfs(int u, int n, vector<int> adj[], vector<pair<int, int> > &b, bool q) {
  queue<int> Q;
  vector<int> d(n + 1, oo);
  d[u] = 0;
  Q.push(u);
  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (auto v : adj[cur]) {
      int dist = d[cur] + 1;
      if (dist >= d[v]) continue;
      d[v] = dist;
      Q.push(v);
      if (q) cost[u][v] = dist;
    }
  }
  for (int i = 1; i <= n; i++) b.push_back({d[i], i});
  sort(b.begin(), b.end());
  while (!b.empty() && b.back().first >= oo) b.pop_back();
  reverse(b.begin(), b.end());
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= n; j++) cost[i][j] = oo;
    cost[i][i] = 0;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    gt[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    bfs(i, n, g, b[i], 1);
    bfs(i, n, gt, bt[i], 0);
  }
  vector<int> ans;
  int best = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      for (int k = 0; k < min(3, (int)bt[i].size()); k++) {
        for (int l = 0; l < min(3, (int)b[j].size()); l++) {
          int u = bt[i][k].second, du = bt[i][k].first;
          int v = b[j][l].second, dv = b[j][l].first;
          int cur_ans = du + cost[i][j] + dv;
          if (cur_ans >= oo || cur_ans <= best) continue;
          set<int> S = {u, i, j, v};
          if (S.size() < 4) continue;
          best = cur_ans;
          ans = {u, i, j, v};
        }
      }
    }
  }
  for (auto x : ans) cout << x << " ";
  cout << '\n';
  return 0;
}
