#include <bits/stdc++.h>
using namespace std;
int n, m;
void bfs(vector<vector<int>> &dist, const vector<vector<int>> &g, int from) {
  queue<int> q;
  q.push(from);
  vector<int> d(n, 1 << 30);
  d[from] = 0;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int to : g[v]) {
      if (d[to] == 1 << 30) {
        d[to] = 1 + d[v];
        q.push(to);
      }
    }
  }
  for (int i = 0; i < n; i++) dist[from][i] = d[i];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n >> m;
  vector<vector<int>> g(n), g_t(n);
  vector<vector<int>> dist(n, vector<int>(n, 1 << 30)),
      dist_t(n, vector<int>(n, 1 << 30));
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g_t[b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    bfs(dist, g, i);
    bfs(dist_t, g_t, i);
  }
  vector<vector<pair<int, int>>> farthest(n), farthest_g(n);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (dist[i][j] != 1 << 30) farthest[i].push_back({dist[i][j], j});
      if (dist_t[i][j] != 1 << 30) farthest_g[i].push_back({dist_t[i][j], j});
    }
    sort(farthest[i].rbegin(), farthest[i].rend());
    sort(farthest_g[i].rbegin(), farthest_g[i].rend());
  }
  int best = -1;
  pair<pair<int, int>, pair<int, int>> ans;
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < n; b++) {
      if (a == b) continue;
      int curr = dist[a][b];
      if (curr == 1 << 30) continue;
      for (int i = 0; i < 3 && i < farthest_g[a].size(); i++) {
        pair<int, int> x = farthest_g[a][i];
        if (a == x.second) continue;
        for (int j = 0; j < 3 && j < farthest[b].size(); j++) {
          pair<int, int> y = farthest[b][j];
          if (y.second == b) continue;
          if (curr + x.first + y.first > best && x.second != b &&
              x.second != y.second && y.second != a) {
            best = curr + x.first + y.first;
            ans = {{x.second, a}, {b, y.second}};
          }
        }
      }
    }
  }
  cout << ans.first.first + 1 << " " << ans.first.second + 1 << " "
       << ans.second.first + 1 << " " << ans.second.second + 1 << '\n';
  return 0;
}
