#include <bits/stdc++.h>
using namespace std;
const int LAR = 1e9;
int n, m, dist[3005][3005], g1[3005][5], g2[3005][5];
vector<int> g[3005];
void bfs(int stt) {
  queue<int> q;
  q.push(stt);
  fill(dist[stt], dist[stt] + n + 1, LAR);
  dist[stt][stt] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int j = 0; j < g[x].size(); j++) {
      if (dist[stt][x] + 1 < dist[stt][g[x][j]]) {
        dist[stt][g[x][j]] = dist[stt][x] + 1;
        q.push(g[x][j]);
      }
    }
  }
}
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++) {
    for (int j = 1; j <= n; j++) {
      if (i == j || dist[i][j] == LAR) continue;
      if (dist[i][j] > dist[i][g1[i][3]] || g1[i][3] == 0) {
        g1[i][3] = j;
        if (dist[i][j] > dist[i][g1[i][2]] || g1[i][2] == 0) {
          swap(g1[i][2], g1[i][3]);
          if (dist[i][j] > dist[i][g1[i][1]] || g1[i][1] == 0)
            swap(g1[i][1], g1[i][2]);
        }
      }
      if (dist[i][j] > dist[g2[j][3]][j] || g2[j][3] == 0) {
        g2[j][3] = i;
        if (dist[i][j] > dist[g2[j][2]][j] || g2[j][2] == 0) {
          swap(g2[j][2], g2[j][3]);
          if (dist[i][j] > dist[g2[j][1]][j] || g2[j][1] == 0) {
            swap(g2[j][1], g2[j][2]);
          }
        }
      }
    }
  }
  int mx = 0, A, B, C, D;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j || dist[i][j] == LAR) continue;
      int ans;
      for (int x = 1; x < 4; x++) {
        int a = g2[i][x];
        for (int y = 1; y < 4; y++) {
          int d = g1[j][y];
          if (a != j && a != d && i != d && a != 0 && d != 0) {
            ans = dist[a][i] + dist[i][j] + dist[j][d];
            if (ans > mx) {
              mx = ans;
              A = a;
              B = i;
              C = j;
              D = d;
            }
          }
        }
      }
    }
  }
  cout << A << " " << B << " " << C << " " << D << endl;
  return 0;
}
