#include <bits/stdc++.h>
using namespace std;
int dist[3001][3001];
set<pair<int, int>> bestin[3001], bestout[3001];
vector<int> graph[3001];
void update(set<pair<int, int>> &best, int d, int u) {
  for (auto e : best)
    if (e.second == u) {
      if (e.first >= d) return;
      best.erase(e);
      best.insert({d, u});
      return;
    }
  best.insert({d, u});
  if (best.size() > 4) best.erase(best.begin());
}
void bfs(int s) {
  queue<int> q;
  dist[s][s] = 0;
  q.push(s);
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int i = 0; i < graph[v].size(); i++) {
      int u = graph[v][i];
      if (dist[s][u] == -1) {
        dist[s][u] = dist[s][v] + 1;
        update(bestin[u], dist[s][u], s);
        update(bestout[s], dist[s][u], u);
        q.push(u);
      }
    }
  }
}
int main() {
  memset(dist, -1, sizeof dist);
  int n, m;
  scanf("%d %d", &n, &m);
  while (m--) {
    int v, u;
    scanf("%d %d", &v, &u);
    graph[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  int a = 1, b = 1, c = 1, d = 1;
  int best = 0;
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= n; j++)
      for (auto k : bestin[i])
        for (auto l : bestout[j]) {
          if (dist[i][j] == -1) continue;
          int distance = k.first + dist[i][j] + l.first;
          int ans[] = {k.second, i, j, l.second};
          bool ok = true;
          for (int i = 0; i < 4; i++)
            for (int j = i + 1; j < 4; j++)
              if (ans[i] == ans[j]) ok = false;
          if (best < distance && ok) {
            best = distance;
            a = ans[0], b = ans[1], c = ans[2], d = ans[3];
          }
        }
  printf("%d %d %d %d", a, b, c, d);
  return 0;
}
