#include <bits/stdc++.h>
using namespace std;
double pi = 3.14159265358979323846264338;
int n, m;
int dis[3001][3001], dis2[3001][3001], md[4][3001][3];
vector<int> bou[3001], bou2[3001];
bool ok[3001];
int ans = -1;
int ak[4];
queue<pair<int, int>> que;
void che(int a, int b, int dist) {
  if (dist >= md[2][a][0]) {
    md[0][a][2] = md[0][a][1], md[0][a][1] = md[0][a][0], md[0][a][0] = b;
    md[2][a][2] = md[2][a][1], md[2][a][1] = md[2][a][0], md[2][a][0] = dist;
  } else if (dist >= md[2][a][1]) {
    md[0][a][2] = md[0][a][1], md[0][a][1] = b;
    md[2][a][2] = md[2][a][1], md[2][a][1] = dist;
  } else if (dist >= md[2][a][2])
    md[0][a][2] = b, md[2][a][2] = dist;
  if (dist >= md[3][b][0]) {
    md[1][b][2] = md[1][b][1], md[1][b][1] = md[1][b][0], md[1][b][0] = a;
    md[3][b][2] = md[3][b][1], md[3][b][1] = md[3][b][0], md[3][b][0] = dist;
  } else if (dist >= md[3][b][1]) {
    md[1][b][2] = md[1][b][1], md[1][b][1] = a;
    md[3][b][2] = md[3][b][1], md[3][b][1] = dist;
  } else if (dist >= md[3][b][2])
    md[1][b][2] = a, md[3][b][2] = dist;
}
void che2(int a, int b) {
  ok[a] = true;
  ok[b] = true;
  int c, d;
  for (int i = 0; i < 3; i++) {
    if (!ok[md[0][b][i]] && md[0][b][i] != 0) {
      ok[md[0][b][i]] = true;
      c = md[2][b][i];
      for (int j = 0; j < 3; j++) {
        if (!ok[md[1][a][j]] && md[1][a][j] != 0) {
          d = md[3][a][j];
          if (dis[a][b] + d + c >= ans) {
            ak[0] = md[1][a][j], ak[1] = a, ak[2] = b, ak[3] = md[0][b][i];
            ans = dis[a][b] + c + d;
          }
        }
      }
      ok[md[0][b][i]] = false;
    }
  }
  ok[a] = false;
  ok[b] = false;
}
void bfs(int a, int b) {
  for (auto k : bou[b]) {
    if (k == a) continue;
    if (dis[a][k] != 0) continue;
    dis[a][k] = dis[a][b] + 1;
    dis2[k][a] = dis[a][k];
    che(a, k, dis[a][k]);
    bou2[a].push_back(k);
    que.push(make_pair(a, k));
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    bou[a].push_back(b);
  }
  for (int i = 1; i <= n; i++) {
    que.push(make_pair(i, i));
    while (!que.empty()) {
      int a, b;
      a = que.front().first;
      b = que.front().second;
      que.pop();
      bfs(a, b);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < bou2[i].size(); j++) {
      int k = bou2[i][j];
      che2(i, k);
    }
  }
  for (int i = 0; i < 4; i++) cout << ak[i] << " ";
  cout << endl;
}
