#include <bits/stdc++.h>
using namespace std;
template <typename T>
using Matrix = vector<vector<T>>;
template <typename T>
Matrix<T> matrix(int R, int C, T x = T()) {
  return Matrix<T>(R, vector<T>(C, x));
}
struct Itinerary {
  int city1, city2, city3, city4;
  int distance;
  Itinerary(int city1, int city2, int city3, int city4, int distance)
      : city1(city1),
        city2(city2),
        city3(city3),
        city4(city4),
        distance(distance) {}
};
bool operator<(const Itinerary& a, const Itinerary& b) {
  return a.distance < b.distance;
}
void bfs(int N, vector<vector<int>>& graph, vector<int>& distance, int source) {
  queue<int> queue;
  distance[source] = 0;
  queue.push(source);
  while (!queue.empty()) {
    int top = queue.front();
    queue.pop();
    for (int next : graph[top])
      if (distance[next] == -1) {
        distance[next] = distance[top] + 1;
        queue.push(next);
      }
  }
}
Itinerary solve(int N, vector<vector<int>>& graph) {
  auto distance = matrix<int>(N, N, -1);
  for (int source = 0; source < N; source++)
    bfs(N, graph, distance[source], source);
  auto city1_options = vector<vector<int>>(N);
  for (int city2 = 0; city2 < N; city2++) {
    auto by_distance = vector<pair<int, int>>();
    for (int city1 = 0; city1 < N; city1++)
      if (distance[city1][city2] != -1)
        by_distance.push_back({distance[city1][city2], city1});
    sort(begin(by_distance), end(by_distance));
    reverse(begin(by_distance), end(by_distance));
    for (int i = 0; i < min(3, (int)by_distance.size()); i++)
      city1_options[city2].push_back(by_distance[i].second);
  }
  auto city4_options = vector<vector<int>>(N);
  for (int city3 = 0; city3 < N; city3++) {
    auto by_distance = vector<pair<int, int>>();
    for (int city4 = 0; city4 < N; city4++)
      if (distance[city3][city4] != -1)
        by_distance.push_back({distance[city3][city4], city4});
    sort(begin(by_distance), end(by_distance));
    reverse(begin(by_distance), end(by_distance));
    for (int i = 0; i < min(3, (int)by_distance.size()); i++)
      city4_options[city3].push_back(by_distance[i].second);
  }
  auto result = Itinerary(0, 0, 0, 0, 0);
  for (int city2 = 0; city2 < N; city2++)
    for (int city3 = 0; city3 < N; city3++) {
      if (distance[city2][city3] == -1) continue;
      for (int city1 : city1_options[city2])
        for (int city4 : city4_options[city3])
          if (city1 != city2 && city1 != city3 && city1 != city4 &&
              city2 != city3 && city2 != city4 && city3 != city4) {
            int d = distance[city1][city2] + distance[city2][city3] +
                    distance[city3][city4];
            result = max(result, Itinerary(city1, city2, city3, city4, d));
          }
    }
  return result;
}
int main() {
  int N, M;
  cin >> N >> M;
  auto graph = vector<vector<int>>(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    graph[u].push_back(v);
  }
  Itinerary answer = solve(N, graph);
  cout << answer.city1 + 1 << " " << answer.city2 + 1 << " " << answer.city3 + 1
       << " " << answer.city4 + 1 << endl;
}
