#include <bits/stdc++.h>
using namespace std;
const int N = 3001;
int n, m, d[N][N], q[N], dq, cq, d1, d2, d3, d4;
vector<int> E[N];
vector<pair<int, int> > D[N], F[N];
void BFS(int start) {
  dq = 0;
  cq = 1;
  q[1] = start;
  d[start][start] = 0;
  while (dq < cq) {
    int u = q[++dq];
    for (int i = 0; i < E[u].size(); i++) {
      int v = E[u][i];
      if (d[start][v] != -1) continue;
      q[++cq] = v;
      d[start][v] = d[start][u] + 1;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    E[u].push_back(v);
  }
  memset(d, 255, sizeof(d));
  ;
  for (int i = 1; i <= n; i++) BFS(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) D[i].push_back(make_pair(d[j][i], j));
    for (int j = 1; j <= n; j++) F[i].push_back(make_pair(d[i][j], j));
    sort(D[i].begin(), D[i].end(), greater<pair<int, int> >());
    sort(F[i].begin(), F[i].end(), greater<pair<int, int> >());
  }
  int res = 0;
  for (int u = 1; u <= n; u++)
    for (int v = 1; v <= n; v++)
      if (u != v && d[u][v] != -1)
        for (int i = 0; i < 3; i++)
          for (int j = 0; j < 3; j++) {
            int x = D[u][i].second;
            int y = F[v][j].second;
            if (x != y && x != u && x != v && y != u && y != v)
              if (d[x][u] != -1 && d[v][y] != -1 && d[u][v] != -1)
                if (res < d[x][u] + d[u][v] + d[v][y]) {
                  res = d[x][u] + d[u][v] + d[v][y];
                  d1 = x;
                  d2 = u;
                  d3 = v;
                  d4 = y;
                }
          }
  cout << d1 << " " << d2 << " " << d3 << " " << d4;
  return 0;
}
