#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3001];
int dis[3001][3001];
vector<pair<int, int> > dist[3001], rdist[3001];
bool comparePairs(const pair<int, int>& lhs, const pair<int, int>& rhs) {
  return lhs.first < rhs.first;
}
int stat[3001];
void dfs(int p, int uy, int diy) {
  queue<pair<int, int> > q;
  q.push(make_pair(p, 0));
  dis[p][p] = diy;
  pair<int, int> u;
  for (int i = 1; i <= 3000; ++i) stat[i] = -1;
  int v;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    int sz = adj[u.first].size();
    if (stat[u.first] == 1) {
      continue;
    }
    for (int i = 0; i < sz; i++) {
      v = adj[u.first][i];
      if (stat[v] == -1) {
        stat[v] = 0;
        q.push(make_pair(v, u.second + 1));
      }
    }
    stat[u.first] = 1;
    dis[p][u.first] = u.second;
  }
}
int main() {
  int n, m, u, v;
  clock_t start;
  double duration;
  start = clock();
  cin >> n >> m;
  while (m--) cin >> u >> v, adj[u].push_back(v);
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) dis[i][j] = 1000000000;
    dis[i][i] = 0;
    dfs(i, i, 0);
    for (int j = 1; j <= n; ++j) {
      if (j == i || dis[i][j] == 1000000000) continue;
      dist[i].push_back(make_pair(dis[i][j], j));
      rdist[j].push_back(make_pair(dis[i][j], i));
    }
    sort(dist[i].begin(), dist[i].end(), comparePairs);
  }
  for (int i = 1; i <= n; ++i)
    sort(rdist[i].begin(), rdist[i].end(), comparePairs);
  int mx = 0, cu;
  vector<int> ans;
  int tu, tv;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (i == j || dis[i][j] == 1000000000) continue;
      if (rdist[i].size() == 0) continue;
      if (dist[j].size() == 0) continue;
      u = rdist[i].size() - 1;
      v = dist[j].size() - 1;
      if (rdist[i][u].second == j) --u;
      if (dist[j][v].second == i) --v;
      if (u < 0 || v < 0) continue;
      if (rdist[i][u].second != dist[j][v].second) {
        cu = rdist[i][u].first + dis[i][j] + dist[j][v].first;
        if (cu > mx) {
          mx = cu;
          ans.clear();
          ans.push_back(rdist[i][u].second);
          ans.push_back(i);
          ans.push_back(j);
          ans.push_back(dist[j][v].second);
        }
      } else {
        if (u > 0) {
          tu = u, tv = v;
          u -= 1;
          if (rdist[i][u].second == j) --u;
          if (dist[j][v].second == i) --v;
          if (u < 0 || v < 0) continue;
          cu = rdist[i][u].first + dis[i][j] + dist[j][v].first;
          if (cu > mx) {
            mx = cu;
            ans.clear();
            ans.push_back(rdist[i][u].second);
            ans.push_back(i);
            ans.push_back(j);
            ans.push_back(dist[j][v].second);
          }
          u = tu, v = tv;
        }
        if (v > 0) {
          tv = v, tu = u;
          v -= 1;
          if (rdist[i][u].second == j) --u;
          if (dist[j][v].second == i) --v;
          if (u < 0 || v < 0) continue;
          cu = rdist[i][u].first + dis[i][j] + dist[j][v].first;
          if (cu > mx) {
            mx = cu;
            ans.clear();
            ans.push_back(rdist[i][u].second);
            ans.push_back(i);
            ans.push_back(j);
            ans.push_back(dist[j][v].second);
          }
          v = tv, u = tu;
        }
      }
    }
  }
  for (int i = 0; i < 4; ++i) cout << ans[i] << " ";
  cout << "\n";
  return 0;
}
