#include <bits/stdc++.h>
using namespace std;
const int Maxn = 3000 + 100;
queue<int> que;
vector<int> nei[Maxn];
long long dis[Maxn][Maxn], n, m, maxkol, ans[4];
vector<pair<long long, int> > maxin[Maxn], maxout[Maxn];
void bfs(int s) {
  for (int i = 0; i < n; i++) dis[s][i] = -1;
  dis[s][s] = 0;
  que.push(s);
  while (!que.empty()) {
    int u = que.front();
    que.pop();
    for (int i = 0; i < (int)nei[u].size(); i++) {
      int v = nei[u][i];
      if (dis[s][v] == -1) {
        dis[s][v] = dis[s][u] + 1;
        que.push(v);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (dis[s][i] != -1 && i != s) {
      maxout[s].push_back(make_pair(dis[s][i], i));
      maxin[i].push_back(make_pair(dis[s][i], s));
    } else {
      maxout[s].push_back(make_pair(-1, -1));
      maxin[i].push_back(make_pair(-1, -1));
    }
  }
  sort(maxout[s].begin(), maxout[s].end());
}
void findm(int u, int v, int tu, int tv) {
  if (u != tv && v != tu && tv != tu && tv != -1 && tu != -1) {
    if (maxkol < dis[tu][u] + dis[u][v] + dis[v][tv]) {
      maxkol = dis[tu][u] + dis[u][v] + dis[v][tv];
      ans[0] = tu, ans[1] = u, ans[2] = v, ans[3] = tv;
    }
  }
  return;
}
int main() {
  cin >> n >> m;
  for (int i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    nei[a - 1].push_back(b - 1);
  }
  for (int i = 0; i < n; i++) {
    bfs(i);
  }
  for (int i = 0; i < n; i++) {
    sort(maxin[i].begin(), maxin[i].end());
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j && dis[i][j] != -1) {
        for (int k = n - 3; k < n; k++) {
          for (int l = n - 3; l < n; l++) {
            findm(i, j, maxin[i][k].second, maxout[j][l].second);
          }
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    cout << ans[i] + 1 << " ";
  }
}
