#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int _x;
  scanf("%d", &_x);
  return _x;
}
const int INF = (int)1e9;
const int mod = (int)1e9 + 7;
const int maxn = (int)3e3 + 5;
const int logn = 20;
const int sqrtn = 1e3 + 5;
int N, M, mark[maxn][maxn];
bool used[maxn], used2[maxn][maxn];
vector<int> road[maxn];
vector<pair<int, int> > q[maxn], w[maxn];
void sp(int root) {
  memset(used, 0, sizeof used);
  mark[root][root] = 0;
  priority_queue<pair<int, int>, vector<pair<int, int> >,
                 greater<pair<int, int> > >
      pq;
  pq.push(pair<int, int>(0, root));
  while (!pq.empty()) {
    int cur = pq.top().second;
    int cost = pq.top().first;
    pq.pop();
    used[cur] = 1;
    for (int i = 0; i < road[cur].size(); i++) {
      if (cost + 1 < mark[root][road[cur][i]]) {
        mark[root][road[cur][i]] = cost + 1;
        pq.push(pair<int, int>(mark[root][road[cur][i]], road[cur][i]));
      }
    }
    while (!pq.empty() && used[pq.top().second]) pq.pop();
    if (pq.empty()) break;
  }
  for (int i = 1; i <= N; i++)
    if (i != root && mark[root][i] <= M) {
      q[root].push_back(pair<int, int>(mark[root][i], i));
      w[i].push_back(pair<int, int>(mark[root][i], root));
      used2[root][i] = 1;
    }
}
int main() {
  memset(mark, 101, sizeof mark);
  int maxx = -1, a1, a2, a3, a4;
  N = read(), M = read();
  for (int i = 1; i <= M; i++) {
    int a = read(), b = read();
    road[a].push_back(b);
  }
  for (int i = 1; i <= N; i++) sp(i);
  for (int i = 1; i <= N; i++)
    sort(q[i].begin(), q[i].end()), sort(w[i].begin(), w[i].end());
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++) {
      if (i == j || !used2[i][j]) continue;
      for (int k = w[i].size() - 1; k >= max(0, (int)w[i].size() - 4); k--)
        for (int l = q[j].size() - 1; l >= max(0, (int)q[j].size() - 4); l--) {
          if (w[i][k].second == q[j][l].second || w[i][k].second == j ||
              q[j][l].second == i)
            continue;
          int cur;
          cur = mark[i][j] + w[i][k].first + q[j][l].first;
          if (cur > maxx) {
            maxx = cur;
            a1 = w[i][k].second, a2 = i, a3 = j, a4 = q[j][l].second;
          }
        }
    }
  printf("%d %d %d %d\n", a1, a2, a3, a4);
  return 0;
}
