#include <bits/stdc++.h>
using namespace std;
int min_dist[3005][3005];
vector<int> furthest_out[3005];
vector<pair<int, int> > X;
vector<pair<int, int> > furthest_in[3005];
vector<int> E[3005];
int n;
void bfs(int source) {
  for (int j = 1; j <= n; j++) min_dist[source][j] = 1 << 30;
  min_dist[source][source] = 0;
  queue<int> Q;
  Q.push(source);
  while (!Q.empty()) {
    int v = Q.front();
    Q.pop();
    int d = min_dist[source][v];
    for (int i = 0; i < E[v].size(); i++) {
      int to = E[v][i];
      if (min_dist[source][to] >= (1 << 30)) {
        min_dist[source][to] = d + 1;
        Q.push(to);
      }
    }
  }
  X.clear();
  for (int i = 1; i <= n; i++) {
    if (i == source) continue;
    if (min_dist[source][i] >= (1 << 30)) continue;
    X.push_back(make_pair(min_dist[source][i], i));
    furthest_in[i].push_back(make_pair(min_dist[source][i], source));
  }
  sort(X.begin(), X.end());
  reverse(X.begin(), X.end());
  for (int i = 0; i < X.size() && i < 5; i++) {
    furthest_out[source].push_back(X[i].second);
  }
}
long long v[222222];
int main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  int m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    E[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  for (int i = 1; i <= n; i++) {
    sort(furthest_in[i].begin(), furthest_in[i].end());
    reverse(furthest_in[i].begin(), furthest_in[i].end());
  }
  long long ans = 0;
  int x = -1, y = -1, z = -1, dd = -1;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (min_dist[i][j] == (1 << 30)) {
        continue;
      }
      for (int k = 0; k < furthest_in[i].size() && k < 6; k++) {
        int a = furthest_in[i][k].second;
        if (i == a || j == a) continue;
        for (int p = 0; p < furthest_out[j].size() && p < 6; p++) {
          int b = furthest_out[j][p];
          if (a == b) continue;
          if (i == b || j == b) continue;
          long long cur = min_dist[a][i] + min_dist[i][j] + min_dist[j][b];
          if (cur > ans) {
            ans = cur;
            x = i;
            y = j;
            z = a;
            dd = b;
          }
        }
      }
    }
  }
  cout << z << " " << x << " " << y << " " << dd << endl;
  return 0;
}
