#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void Cin(T& a) {
  int c = getchar(), sign = 0;
  a = 0;
  while (c < '0' || c > '9') sign += (c == '-'), c = getchar();
  while (c >= '0' && c <= '9') a = (a << 1) + (a << 3) + c - 48, c = getchar();
  if (sign & 1) a = -a;
}
template <typename T, typename... Args>
inline void Cin(T& a, Args&... args) {
  Cin(a);
  Cin(args...);
}
const int maxn = 3e3 + 5;
int N, M;
vector<pair<int, int>> hIn[maxn], hOut[maxn];
vector<int> adj[maxn], D[maxn];
vector<int> bfs(int s) {
  vector<int> d(N + 5, -1);
  deque<int> dq;
  dq.push_back(s);
  d[s] = 0;
  while (dq.size()) {
    auto now = dq.front();
    dq.pop_front();
    for (int it : adj[now]) {
      if (d[it] == -1) {
        d[it] = d[now] + 1;
        dq.push_back(it);
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    if (i != s) {
      hOut[s].push_back({d[i], i});
      hIn[i].push_back({d[i], s});
    }
  }
  return d;
}
signed main(void) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  Cin(N, M);
  for (int i = 1, u, v; i <= M; ++i) {
    Cin(u, v);
    adj[u].push_back(v);
  }
  for (int i = 1; i <= N; ++i) D[i] = bfs(i);
  for (int i = 1; i <= N; ++i) {
    sort(hIn[i].rbegin(), hIn[i].rend());
    sort(hOut[i].rbegin(), hOut[i].rend());
  }
  int x, y, z, t, Max = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = 1; j <= N; ++j) {
      if (i == j) continue;
      if (D[i][j] == -1) continue;
      for (int p = 0; p < min(3, (int)hIn[i].size()); ++p) {
        for (int q = 0; q < min(3, (int)hOut[j].size()); ++q) {
          int val = D[i][j] + hIn[i][p].first + hOut[j][q].first;
          int u = hIn[i][p].second, v = hOut[j][q].second;
          if (u == v) continue;
          if (u == j) continue;
          if (u == i) continue;
          if (v == j) continue;
          if (v == i) continue;
          if (Max < val) {
            Max = val;
            x = u;
            y = i;
            z = j;
            t = v;
          }
        }
      }
    }
  }
  cout << x << ' ' << y << ' ' << z << ' ' << t;
}
