#include <bits/stdc++.h>
using namespace std;
struct comp {
  bool operator()(pair<int, int> a, pair<int, int> b) {
    return a.first < b.first;
  }
};
vector<int> g[3005];
priority_queue<pair<int, int>, vector<pair<int, int>>, comp> in[3005],
    out[3005];
int SD[3005][3005];
int n;
int sol[4];
int maxdist = 0;
void bfs(int u) {
  int dist[n];
  for (int i = 0; i < n; i++) dist[i] = 1000000000;
  int i;
  bool v[n];
  memset(v, false, sizeof(v));
  queue<pair<int, int>> q;
  q.push(make_pair(u, 0));
  v[u] = true;
  dist[u] = 0;
  while (!q.empty()) {
    pair<int, int> x = q.front();
    q.pop();
    for (i = 0; i < g[x.first].size(); i++) {
      if (!v[g[x.first][i]]) {
        v[g[x.first][i]] = true;
        dist[g[x.first][i]] = x.second + 1;
        q.push(make_pair(g[x.first][i], x.second + 1));
      }
    }
  }
  for (i = 0; i < n; i++) {
    SD[u][i] = dist[i];
    if (dist[i] != 1000000000 && i != u && dist[i] > 0) {
      in[i].push(make_pair(dist[i], u));
      out[u].push(make_pair(dist[i], i));
    }
  }
}
void compute(pair<int, int> x[], pair<int, int> y[], int X, int Y) {
  int i, j;
  for (i = 0; i < 3; i++) {
    for (j = 0; j < 3; j++) {
      if (x[i].second != Y && x[i].second != y[j].second && y[j].second != X) {
        int d = x[i].first + y[j].first + SD[X][Y];
        if (d > maxdist) {
          maxdist = d;
          sol[0] = x[i].second;
          sol[1] = X;
          sol[3] = y[j].second;
          sol[2] = Y;
        }
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int i, j, k, m;
  cin >> n >> m;
  for (i = 0; i < m; i++) {
    cin >> j >> k;
    if (i != k)
      ;
    g[j - 1].push_back(k - 1);
  }
  for (i = 0; i < n; i++) {
    bfs(i);
  }
  int d;
  pair<int, int> x[3], y[3];
  for (i = 0; i < n; i++) {
    while (in[i].size() < 3) in[i].push(make_pair(-1, -1));
    while (out[i].size() < 3) out[i].push(make_pair(-1, -1));
  }
  for (i = 0; i < n; i++) {
    x[0] = in[i].top();
    in[i].pop();
    x[1] = in[i].top();
    in[i].pop();
    x[2] = in[i].top();
    in[i].pop();
    if (i == 1) {
    }
    for (j = 0; j < n; j++) {
      if (i == j) continue;
      if (SD[i][j] == 1000000000) continue;
      y[0] = out[j].top();
      out[j].pop();
      y[1] = out[j].top();
      out[j].pop();
      y[2] = out[j].top();
      out[j].pop();
      out[j].push(y[0]);
      out[j].push(y[1]);
      out[j].push(y[2]);
      compute(x, y, i, j);
    }
  }
  cout << sol[0] + 1 << " " << sol[1] + 1 << " " << sol[2] + 1 << " "
       << sol[3] + 1 << endl;
  return 0;
}
