#include <bits/stdc++.h>
using namespace std;
vector<int> g[3050];
int n, m;
int vis[100050];
int d[100050];
int to[3050][3050];
int from[3050][3050];
int ans[4];
vector<pair<int, int> > From[3050];
vector<pair<int, int> > To[3050];
int sum = 0;
void bfs(int rt) {
  memset(d, -0x3f3f3f3f, sizeof(d));
  memset(vis, 0, sizeof(vis));
  queue<int> q;
  q.push(rt);
  vis[rt] = 1;
  d[rt] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < g[u].size(); i++) {
      int v = g[u][i];
      if (!vis[v]) {
        vis[v] = 1;
        d[v] = d[u] + 1;
        q.push(v);
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    bfs(i);
    for (int j = 1; j <= n; j++) from[i][j] = d[j];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      to[i][j] = from[j][i];
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) From[i].push_back(make_pair(from[i][j], j));
    sort(From[i].begin(), From[i].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) To[i].push_back(make_pair(to[i][j], j));
    sort(To[i].begin(), To[i].end());
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      int dis = from[i][j];
      if (dis < 0) continue;
      int aa[5], bb[5];
      int cnt = 0;
      for (int k = To[i].size() - 1; k >= To[i].size() - 3; k--) {
        aa[cnt++] = To[i][k].second;
      }
      cnt = 0;
      for (int k = From[j].size() - 1; k >= From[j].size() - 3; k--) {
        bb[cnt++] = From[j][k].second;
      }
      int cnt1 = 0, cnt2 = 0;
      for (cnt1 = 0; cnt1 < 3; cnt1++) {
        for (cnt2 = 0; cnt2 < 3; cnt2++) {
          if (aa[cnt1] != i && i != bb[cnt2] && aa[cnt1] != j &&
              bb[cnt2] != j && aa[cnt1] != bb[cnt2]) {
            int Sum = from[aa[cnt1]][i] + dis + from[j][bb[cnt2]];
            if (from[aa[cnt1]][i] < 0 || from[j][bb[cnt2]] < 0) continue;
            if (Sum > sum) {
              sum = Sum;
              ans[0] = aa[cnt1];
              ans[1] = i;
              ans[2] = j;
              ans[3] = bb[cnt2];
            }
          }
        }
      }
    }
  }
  cout << ans[0] << " " << ans[1] << " " << ans[2] << " " << ans[3] << endl;
  return 0;
}
