#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
vector<int> g[N];
int dis[N][N];
vector<pair<int, int>> in[N], out[N];
int n, m;
int ans = 0;
vector<int> moves(4, 0);
void bfs(int x) {
  dis[x][x] = 0;
  queue<int> q;
  q.push(x);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    int curDistance = dis[x][cur];
    for (auto k : g[cur]) {
      if (curDistance + 1 < dis[x][k]) {
        dis[x][k] = curDistance + 1;
        q.push(k);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (dis[x][i] < INT_MAX) {
      in[i].push_back(make_pair(dis[x][i], x));
      out[x].push_back(make_pair(dis[x][i], i));
    }
  }
}
void f(int b, int c) {
  if (b == c) return;
  for (int i = 0; i < min(6, (int)in[b].size()); i++) {
    int a = in[b][i].second;
    if (a == b || a == c) continue;
    for (int j = 0; j < min(6, (int)out[c].size()); ++j) {
      int d = out[c][j].second;
      if (d == a || d == b || d == c) continue;
      int total = dis[a][b] + dis[b][c] + dis[c][d];
      if (total > ans) {
        ans = total;
        moves[0] = a;
        moves[1] = b;
        moves[2] = c;
        moves[3] = d;
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++) {
      dis[i][j] = INT_MAX;
    }
  }
  while (m--) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  for (int i = 1; i <= n; i++) {
    sort(in[i].begin(), in[i].end());
    reverse(in[i].begin(), in[i].end());
    sort(out[i].begin(), out[i].end());
    reverse(out[i].begin(), out[i].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (dis[i][j] < INT_MAX) {
        f(i, j);
      }
    }
  }
  for (auto x : moves) cout << x << " ";
}
