#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3002], rev[3002];
int dis[3002][3002], rdis[3002][3002];
bool vis[3002];
int mxd[3002][3], rmxd[3002][3];
void bfs(int u, int n) {
  queue<int> q;
  q.push(u);
  for (int i = 1; i <= n; i++) vis[i] = 0;
  dis[u][u] = 0;
  vis[u] = 1;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto x : adj[v]) {
      if (!vis[x]) {
        dis[u][x] = dis[u][v] + 1;
        vis[x] = 1;
        q.push(x);
      }
    }
  }
  pair<int, int> ar[n];
  for (int i = 1; i <= n; i++) {
    ar[i - 1] = {dis[u][i], i};
  }
  sort(ar, ar + n);
  mxd[u][0] = ar[n - 1].second;
  mxd[u][1] = ar[n - 2].second;
  mxd[u][2] = ar[n - 3].second;
  for (int i = 1; i <= n; i++) vis[i] = 0;
  q.push(u);
  vis[u] = 1;
  rdis[u][u] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (auto x : rev[v]) {
      if (!vis[x]) {
        rdis[u][x] = rdis[u][v] + 1;
        vis[x] = 1;
        q.push(x);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    ar[i - 1] = {rdis[u][i], i};
  }
  sort(ar, ar + n);
  rmxd[u][0] = ar[n - 1].second;
  rmxd[u][1] = ar[n - 2].second;
  rmxd[u][2] = ar[n - 3].second;
}
int main() {
  int n, m, i, j, k, l, p, u, v, q, ans = 0;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> u >> v;
    if (u != v) {
      adj[u].push_back(v);
      rev[v].push_back(u);
    }
  }
  for (i = 0; i <= n; i++)
    for (j = 0; j <= n; j++) dis[i][j] = rdis[i][j] = -1e5;
  for (i = 1; i <= n; i++) {
    bfs(i, n);
  }
  int ar_ans[4];
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++) {
      if (i == j) continue;
      for (p = 0; p < 3; p++) {
        for (q = 0; q < 3; q++) {
          if (i == mxd[j][q] || j == rmxd[i][p] || i == rmxd[i][p] ||
              j == mxd[j][q] || rmxd[i][p] == mxd[j][q])
            continue;
          if (ans < rdis[i][rmxd[i][p]] + dis[i][j] + dis[j][mxd[j][q]]) {
            ans = rdis[i][rmxd[i][p]] + dis[i][j] + dis[j][mxd[j][q]];
            ar_ans[0] = rmxd[i][p];
            ar_ans[1] = i;
            ar_ans[2] = j;
            ar_ans[3] = mxd[j][q];
          }
        }
      }
    }
  }
  for (int y : ar_ans) {
    cout << y << " ";
  }
  return 0;
}
