#include <bits/stdc++.h>
using namespace std;
int n, m, ans, seq[4], d[3005][3005], MaxT[3005][3005], Max[3005][3005], row;
vector<vector<int>> g;
bool comp(int a, int b) { return d[row][a] > d[row][b]; }
bool compT(int a, int b) { return d[a][row] > d[b][row]; }
void Dijkstra(int s) {
  priority_queue<pair<int, int>> pq;
  pq.push({0, s});
  while (!pq.empty()) {
    int dist = -pq.top().first, x = pq.top().second;
    pq.pop();
    if (d[s][x] != -1) continue;
    d[s][x] = dist;
    for (int adj : g[x]) {
      if (d[s][adj] != -1) continue;
      pq.push({-dist - 1, adj});
    }
  }
}
void sol(int A, int B, int C, int D) {
  if (d[A][B] == -1 || d[B][C] == -1 || d[C][D] == -1) return;
  if (d[A][B] + d[B][C] + d[C][D] > ans) {
    ans = d[A][B] + d[B][C] + d[C][D];
    seq[0] = A;
    seq[1] = B;
    seq[2] = C;
    seq[3] = D;
  }
}
int main() {
  cin >> n >> m;
  g.resize(n + 1);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      d[i][j] = -1;
    }
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) Dijkstra(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      MaxT[i][j] = j;
      Max[i][j] = j;
    }
  }
  for (row = 1; row <= n; row++) {
    sort(Max[row] + 1, Max[row] + n + 1, comp);
    sort(MaxT[row] + 1, MaxT[row] + n + 1, compT);
  }
  for (int B = 1; B <= n; B++) {
    for (int C = 1; C <= n; C++) {
      if (B == C) continue;
      for (int i = 1; i < 3; i++) {
        for (int j = 1; j < 3; j++) {
          int A = MaxT[B][i], D = Max[C][j];
          if (A == B || A == C || A == D || D == B || D == C) continue;
          sol(A, B, C, D);
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) cout << seq[i] << " ";
  return 0;
}
