#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3010;
const int INF = 0x3f3f3f3f;
int dist[MAXN][MAXN];
vector<int> grafo[MAXN], c1[MAXN], c2[MAXN];
bool vis[MAXN];
int n, m;
void bfs(int x) {
  queue<int> fila;
  dist[x][x] = 0;
  fila.push(x);
  while (!fila.empty()) {
    int at = fila.front();
    vis[at] = true;
    for (auto i : grafo[at]) {
      if (vis[i] == true) continue;
      dist[x][i] = dist[x][at] + 1;
      vis[i] = true;
      fila.push(i);
    }
    fila.pop();
  }
}
void f(int x) {
  priority_queue<pair<int, int>> p;
  for (int i = 1; i <= n; i++) {
    if (dist[i][x] != INF && i != x) p.push({dist[i][x], i});
  }
  for (int i = 1; i <= 4; i++) {
    if (p.empty() == true) break;
    pair<int, int> at = p.top();
    c2[x].push_back(at.second);
    p.pop();
  }
  while (!p.empty()) p.pop();
  for (int i = 1; i <= n; i++) {
    if (dist[x][i] != INF && i != x) p.push({dist[x][i], i});
  }
  for (int i = 1; i <= 4; i++) {
    if (p.empty() == true) break;
    pair<int, int> at = p.top();
    c1[x].push_back(at.second);
    p.pop();
  }
}
int main() {
  memset(dist, INF, sizeof dist);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    grafo[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) {
    memset(vis, false, sizeof vis);
    bfs(i);
  }
  for (int i = 1; i <= n; i++) {
    f(i);
  }
  int res = 0;
  int A = 0, B = 0, C = 0, D = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      for (auto k : c2[i]) {
        for (auto l : c1[j]) {
          if (dist[i][j] == INF) continue;
          if (i == j || i == l) continue;
          if (j == k || k == l) continue;
          int d = dist[k][i] + dist[i][j] + dist[j][l];
          if (d > res) {
            res = d;
            A = k, B = i, C = j, D = l;
          }
        }
      }
    }
  }
  cout << A << " " << B << " " << C << " " << D << endl;
}
