#include <bits/stdc++.h>
using namespace std;
const int N = 3000 + 1;
int n, m;
vector<int> G[N];
vector<pair<int, int> > e[N], ein[N];
int d[N][N];
int kq1, kq2, kq3, kq4;
void bfs(int x) {
  for (int i = 1; i <= n; ++i) d[x][i] = -1;
  d[x][x] = 0;
  queue<int> Q;
  Q.push(x);
  while (!Q.empty()) {
    int u = Q.front();
    Q.pop();
    for (int v : G[u])
      if (d[x][v] == -1) {
        d[x][v] = d[x][u] + 1;
        Q.push(v);
      }
  }
  vector<pair<int, int> > a;
  for (int i = 1; i <= n; ++i) a.push_back({d[x][i], i});
  sort(a.begin(), a.end());
  if (a[n - 3].second != x) e[x].push_back(a[n - 3]);
  if (a[n - 2].second != x) e[x].push_back(a[n - 2]);
  if (a[n - 1].second != x) e[x].push_back(a[n - 1]);
}
void code() {
  int mx = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (d[i][j] != -1 && i != j) {
        for (pair<int, int> a : ein[i])
          for (pair<int, int> b : e[j])
            if (a.second != b.second && a.second != j && b.second != i) {
              if (mx < d[a.second][i] + d[i][j] + d[j][b.second]) {
                mx = d[a.second][i] + d[i][j] + d[j][b.second];
                kq1 = a.second;
                kq2 = i;
                kq3 = j;
                kq4 = b.second;
              }
            }
      }
  cerr << mx << " ";
  cout << kq1 << " " << kq2 << " " << kq3 << " " << kq4;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
  }
  for (int i = 1; i <= n; ++i) bfs(i);
  for (int i = 1; i <= n; ++i) {
    vector<pair<int, int> > a;
    for (int j = 1; j <= n; ++j) a.push_back({d[j][i], j});
    sort(a.begin(), a.end());
    if (a[n - 3].second != i) ein[i].push_back(a[n - 3]);
    if (a[n - 2].second != i) ein[i].push_back(a[n - 2]);
    if (a[n - 1].second != i) ein[i].push_back(a[n - 1]);
  }
  code();
}
