#include <bits/stdc++.h>
using namespace std;
const int MAXVERTEX = 3000;
int visited[MAXVERTEX];
int dist[MAXVERTEX][MAXVERTEX];
set<int> graph[MAXVERTEX];
vector<int> best_to[MAXVERTEX];
vector<int> best_from[MAXVERTEX];
int main() {
  int i, n_vertices, n_edges;
  cin >> n_vertices >> n_edges;
  for (i = 0; i < n_edges; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    graph[a].insert(b);
  }
  memset(dist, 0xff, sizeof(dist));
  int source;
  for (source = 0; source < n_vertices; source++) {
    memset(visited, 0, sizeof(visited));
    queue<pair<int, int> > q;
    q.push({source, 0});
    visited[source] = 1;
    while (!q.empty()) {
      pair<int, int> tmp = q.front();
      q.pop();
      int vertex = tmp.first;
      int currentdist = tmp.second;
      dist[source][vertex] = currentdist;
      for (int nextvertex : graph[vertex])
        if (!visited[nextvertex]) {
          q.push({nextvertex, currentdist + 1});
          visited[nextvertex] = 1;
        }
    }
  }
  int A, B;
  for (A = 0; A < n_vertices; A++) {
    vector<pair<int, int> > tmp;
    for (B = 0; B < n_vertices; B++)
      if (dist[A][B] > 0) tmp.push_back({dist[A][B], B});
    sort(tmp.begin(), tmp.end());
    reverse(tmp.begin(), tmp.end());
    for (i = 0; i < 3; i++)
      if (i < tmp.size()) best_from[A].push_back(tmp[i].second);
  }
  for (B = 0; B < n_vertices; B++) {
    vector<pair<int, int> > tmp;
    for (A = 0; A < n_vertices; A++)
      if (dist[A][B] > 0) tmp.push_back({dist[A][B], A});
    sort(tmp.begin(), tmp.end());
    reverse(tmp.begin(), tmp.end());
    for (i = 0; i < 3; i++)
      if (i < tmp.size()) best_to[B].push_back(tmp[i].second);
  }
  vector<int> res;
  int bestlength = 0;
  for (A = 0; A < n_vertices; A++)
    for (B = 0; B < n_vertices; B++)
      if (dist[A][B] > 0) {
        for (int start : best_to[A])
          for (int end : best_from[B]) {
            if (start == A || start == B || start == end || A == B ||
                A == end || B == end)
              continue;
            int length = dist[start][A] + dist[A][B] + dist[B][end];
            if (length > bestlength) {
              bestlength = length;
              res = {start, A, B, end};
            }
          }
      }
  for (int e : res) cout << e + 1 << " ";
  cout << endl;
  return 0;
}
