#include <bits/stdc++.h>
using namespace std;
const int maxn = 3002;
vector<int> g[maxn];
int mp[maxn][maxn], n, m, vis[maxn];
const int inf = 1 << 20;
void bfs(int s) {
  queue<int> q;
  q.push(s);
  memset(vis, 0, sizeof vis);
  vis[s] = 1;
  while (!q.empty()) {
    int t = q.front();
    q.pop();
    for (int tt : g[t]) {
      if (!vis[tt]) {
        vis[tt] = 1;
        mp[s][tt] = mp[s][t] + 1;
        q.push(tt);
      }
    }
  }
}
vector<pair<int, int> > pre[maxn], las[maxn];
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      if (i == j)
        mp[i][j] = 0;
      else
        mp[i][j] = inf;
  for (int i = 1; i <= n; i++) mp[i][i] = 0;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    g[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++) {
      if (i != j) {
        if (mp[i][j] != inf) {
          las[i].push_back({mp[i][j], j});
        }
        if (mp[j][i] != inf) {
          pre[i].push_back({mp[j][i], j});
        }
      }
    }
    sort(pre[i].begin(), pre[i].end(), cmp);
    sort(las[i].begin(), las[i].end(), cmp);
  }
  int sum = 0, res[4];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i != j && mp[i][j] != inf) {
        int cntk = las[j].size();
        for (int k = 0; k < min(3, cntk); k++) {
          if (i != las[j][k].second && j != las[j][k].second) {
            int cnte = pre[i].size();
            for (int e = 0; e < min(3, cnte); e++) {
              if (pre[i][e].second != i && pre[i][e].second != j &&
                  pre[i][e].second != las[j][k].second) {
                if (sum < mp[pre[i][e].second][i] + mp[i][j] +
                              mp[j][las[j][k].second]) {
                  sum = mp[pre[i][e].second][i] + mp[i][j] +
                        mp[j][las[j][k].second];
                  res[0] = pre[i][e].second, res[1] = i, res[2] = j,
                  res[3] = las[j][k].second;
                }
              }
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) cout << res[i] << " ";
  return 0;
}
