#include <bits/stdc++.h>
std::vector<int> a[3005];
std::vector<std::pair<int, int> > f[3005], g[3005];
int n, m, aa, bb, cc, dd, dis[3005][3005];
void add(int x, int y) { a[x].push_back(y); }
void bfs(int s) {
  std::queue<int> q;
  for (int i = 1; i <= n; i++) dis[s][i] = 100000;
  dis[s][s] = 0;
  q.push(s);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < a[v].size(); i++) {
      int u = a[v][i];
      if (dis[s][u] == 100000) dis[s][u] = dis[s][v] + 1, q.push(u);
    }
  }
}
int d(int x, int y) { return dis[x][y] == 100000 ? -1000000 : dis[x][y]; }
void solve() {
  int ans = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (int p = 0; p <= 2; p++)
        for (int q = 0; q <= 2; q++) {
          int v = g[i][p].second, u = f[j][q].second;
          if (i == j || i == v || i == u || j == v || j == u || v == u)
            continue;
          int now = d(v, i) + d(i, j) + d(j, u);
          if (now > ans) aa = v, bb = i, cc = j, dd = u, ans = now;
        }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) dis[i][j] = d(i, j);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) f[i].push_back(std::make_pair(-dis[i][j], j));
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++) g[j].push_back(std::make_pair(-dis[i][j], i));
  for (int i = 1; i <= n; i++) std::sort(f[i].begin(), f[i].end());
  for (int i = 1; i <= n; i++) std::sort(g[i].begin(), g[i].end());
  solve();
  printf("%d %d %d %d\n", aa, bb, cc, dd);
  return 0;
}
