#include <bits/stdc++.h>
using namespace std;
const int N = 3055;
const int inf = 1e9;
bool used[N][N];
struct kek {
  int q[4], w[4];
  void up(int first, int second) {
    if (first > q[0]) {
      q[3] = q[2];
      w[3] = w[2];
      q[2] = q[1];
      w[2] = w[1];
      q[1] = q[0];
      w[1] = w[0];
      q[0] = first;
      w[0] = second;
    } else if (first > q[1]) {
      q[3] = q[2];
      w[3] = w[2];
      q[2] = q[1];
      w[2] = w[1];
      q[1] = first;
      w[1] = second;
    } else if (first > q[2]) {
      q[3] = q[2];
      w[3] = w[2];
      q[2] = first;
      w[2] = second;
    } else if (first > q[3]) {
      q[3] = first;
      w[3] = second;
    }
  }
};
vector<int> g[N];
int gl;
int d[N][N];
kek lel[N];
kek lol[N];
kek fit;
priority_queue<pair<int, int>, vector<pair<int, int> >,
               greater<pair<int, int> > >
    q;
void dfs() {
  q.push(make_pair(0, gl));
  while (!q.empty()) {
    int v = q.top().second;
    int cost = q.top().first;
    q.pop();
    if (d[gl][v] != cost) continue;
    for (int i = 0; i < g[v].size(); ++i) {
      if (d[gl][v] + 1 < d[gl][g[v][i]]) {
        d[gl][g[v][i]] = d[gl][v] + 1;
        q.push(make_pair(d[gl][v] + 1, g[v][i]));
      }
    }
  }
}
int n, m, first, second;
int mx, v1, v2, v3, v4;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    cin >> first >> second;
    g[first].push_back(second);
  }
  for (int i = 0; i < 4; ++i) fit.q[i] = fit.w[i] = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j) d[i][j] = inf;
  for (int i = 1; i <= n; ++i) {
    gl = i;
    d[i][i] = 0;
    dfs();
  }
  for (int i = 1; i <= n; ++i) lol[i] = lel[i] = fit;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      if (i != j & d[i][j] != inf) lel[i].up(d[i][j], j), lol[j].up(d[i][j], i);
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= n; ++j)
      for (int k = 0; k < 4; ++k)
        for (int z = 0; z < 4; ++z) {
          if (d[i][j] == inf) continue;
          int q1 = lol[i].q[k];
          int w1 = lol[i].w[k];
          int q2 = lel[j].q[z];
          int w2 = lel[j].w[z];
          if (i != j && i != w1 && i != w2 && j != w1 && j != w2 && w1 != w2 &&
              w1 != 0 && w2 != 0) {
            int ans = d[i][j] + q1 + q2;
            if (ans > mx) {
              mx = ans;
              v1 = w1;
              v2 = i;
              v3 = j;
              v4 = w2;
            }
          }
        }
  cout << v1 << ' ' << v2 << ' ' << v3 << ' ' << v4;
}
