#include <bits/stdc++.h>
using namespace std;
const int N = 3004;
int D[N][N];
int n, m;
vector<int> G[N];
void bfs(int s) {
  queue<int> q;
  q.push(s);
  D[s][s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (auto v : G[u]) {
      if (D[s][v] == -1) {
        D[s][v] = D[s][u] + 1;
        q.push(v);
      }
    }
  }
}
vector<pair<int, int> > Y[N], Z[N];
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    G[u].push_back(v);
  }
  memset(D, 0xff, sizeof D);
  for (int s = 1; s <= n; s++) bfs(s);
  int a, b, c, d, opt = 0;
  for (int y = 1; y <= n; y++) {
    for (int x = 1; x <= n; x++)
      if (x != y && D[x][y] != -1) {
        Y[y].emplace_back(D[x][y], x);
      }
    sort(Y[y].begin(), Y[y].end());
    reverse(Y[y].begin(), Y[y].end());
    if (Y[y].size() > 4) Y[y].resize(4);
  }
  for (int z = 1; z <= n; z++) {
    for (int t = 1; t <= n; t++)
      if (t != z && D[z][t] != -1) {
        Z[z].emplace_back(D[z][t], t);
      }
    sort(Z[z].begin(), Z[z].end());
    reverse(Z[z].begin(), Z[z].end());
    if (Z[z].size() > 4) Z[z].resize(4);
  }
  for (int y = 1; y <= n; y++) {
    for (int z = 1; z <= n; z++)
      if (z != y && D[y][z] != -1) {
        for (auto xx : Y[y])
          for (auto tt : Z[z]) {
            int x = xx.second;
            int t = tt.second;
            if (x != t && x != z && t != y) {
              int sum = D[x][y] + D[y][z] + D[z][t];
              if (sum > opt) {
                opt = sum;
                tie(a, b, c, d) = make_tuple(x, y, z, t);
              }
            }
          }
      }
  }
  cout << a << " " << b << " " << c << " " << d << endl;
  return 0;
}
