#include <bits/stdc++.h>
using namespace std;
inline char nc() {
  static char buf[100000], *p1, *p2;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
template <class T>
inline void rd(T& x) {
  x = 0;
  char ch = nc();
  for (; ch < '0' || ch > '9'; ch = nc())
    ;
  for (; ch >= '0' && ch <= '9'; ch = nc()) x = x * 10 - 48 + ch;
}
const int maxn = 3000 + 10;
vector<int> G[maxn];
vector<pair<int, int> > itoj[maxn], ktol[maxn];
int dis[maxn][maxn];
int vis[maxn];
int n, m;
const int inf = 0x3f3f3f3f;
inline void bfs(int src) {
  for (int i = 1; i <= n; i++) dis[src][i] = inf;
  memset(vis, 0, sizeof(vis));
  queue<int> q;
  q.push(src);
  vis[src] = 1;
  dis[src][src] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (!vis[v]) {
        dis[src][v] = dis[src][u] + 1;
        vis[v] = 1;
        q.push(v);
      }
    }
  }
}
bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; }
int main() {
  rd(n);
  rd(m);
  for (int u, v; m--;) {
    rd(u);
    rd(v);
    G[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    bfs(i);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (dis[i][j] != inf) {
        itoj[j].push_back(make_pair(dis[i][j], i));
        ktol[i].push_back(make_pair(dis[i][j], j));
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(itoj[i].begin(), itoj[i].end(), cmp);
    sort(ktol[i].begin(), ktol[i].end(), cmp);
  }
  int a, b, c, d, mx = -1;
  for (int j = 1; j <= n; j++) {
    for (int k = 1; k <= n; k++) {
      if (j == k || dis[j][k] == inf) continue;
      for (int i = 0; i < 4 && i < itoj[j].size(); i++) {
        if (itoj[j][i].second == k) continue;
        for (int l = 0; l < 4 && l < ktol[k].size(); l++) {
          if (ktol[k][l].second == itoj[j][i].second || ktol[k][l].second == j)
            continue;
          int dd = itoj[j][i].first + ktol[k][l].first + dis[j][k];
          if (dd > mx) {
            mx = dd;
            a = itoj[j][i].second;
            b = j;
            c = k;
            d = ktol[k][l].second;
          }
        }
      }
    }
  }
  printf("%d %d %d %d", a, b, c, d);
  return 0;
}
