#include <bits/stdc++.h>
using namespace std;
int n, m;
const int N = 3010;
int d[N][N];
vector<int> e[N];
void bfs(int from) {
  vector<int> q;
  q.push_back(from);
  d[from][from] = 0;
  int l = 0;
  int v;
  while (l < q.size()) {
    v = q[l++];
    for (auto to : e[v]) {
      if (d[from][to] != 1e9) continue;
      q.push_back(to);
      d[from][to] = d[from][v] + 1;
    }
  }
}
vector<int> topfrom[N], topto[N];
vector<int> t[N];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--, b--;
    e[a].push_back(b);
  }
  for (int i = 0; i < N; i++)
    for (int j = 0; j < N; j++) d[i][j] = 1e9;
  for (int i = 0; i < n; i++) bfs(i);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][j] == 1e9) continue;
      t[d[i][j]].push_back(j);
    }
    for (int j = N - 1; j > 0; j--) {
      for (auto el : t[j]) {
        if (topto[i].size() < 4)
          topto[i].push_back(el);
        else
          break;
      }
      t[j].clear();
    }
    t[0].clear();
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[j][i] == 1e9) continue;
      t[d[j][i]].push_back(j);
    }
    for (int j = N - 1; j > 0; j--) {
      for (auto el : t[j]) {
        if (topfrom[i].size() < 4)
          topfrom[i].push_back(el);
        else
          break;
      }
      t[j].clear();
    }
    t[0].clear();
  }
  int ans = -1;
  pair<int, int> u;
  pair<int, int> r;
  for (int a = 0; a < n; a++) {
    for (int b = 0; b < n; b++) {
      if (a == b) continue;
      if (d[a][b] == 1e9) continue;
      for (auto k : topfrom[a]) {
        if (k == b || k == a) continue;
        for (auto g : topto[b]) {
          if (g == k || g == b || g == a) continue;
          int dst = d[k][a] + d[a][b] + d[b][g];
          if (dst > ans) {
            ans = dst;
            u = make_pair(k, a);
            r = make_pair(b, g);
          }
        }
      }
    }
  }
  printf("%d %d %d %d\n", u.first + 1, u.second + 1, r.first + 1, 1 + r.second);
  return 0;
}
