#include <bits/stdc++.h>
using namespace std;
const int Maxn = 5555, Inf = 1e9;
int n, m;
vector<int> G[Maxn];
vector<pair<int, int> > V1[Maxn], V2[Maxn];
int d[Maxn][Maxn];
void bfs(int idx) {
  for (int i = 1; i <= n; i++) d[idx][i] = i == idx ? 0 : Inf;
  queue<int> q;
  q.push(idx);
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (d[idx][v] == Inf) {
        d[idx][v] = d[idx][u] + 1;
        q.push(v);
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    if (i != idx && d[idx][i] != Inf)
      V1[idx].push_back(pair<int, int>(d[idx][i], i)),
          V2[i].push_back(pair<int, int>(d[idx][i], idx));
  }
}
int main() {
  scanf("%d%d", &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 i = 1; i <= n; i++) {
    sort(V1[i].begin(), V1[i].end(), greater<pair<int, int> >());
    sort(V2[i].begin(), V2[i].end(), greater<pair<int, int> >());
  }
  int ans = -1;
  vector<int> rep(4, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j || d[i][j] == Inf) continue;
      for (int k1 = 0; k1 < 3 && k1 < V2[i].size(); k1++) {
        for (int k2 = 0; k2 < 3 && k2 < V1[j].size(); k2++) {
          if (V2[i][k1].second != j && V1[j][k2].second != i &&
              V2[i][k1].second != V1[j][k2].second) {
            int tmp = V2[i][k1].first + V1[j][k2].first + d[i][j];
            if (ans < tmp) {
              ans = tmp;
              rep[0] = V2[i][k1].second, rep[1] = i;
              rep[2] = j, rep[3] = V1[j][k2].second;
            }
          }
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) printf("%d ", rep[i]);
}
