#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 10;
const int INF = 0x3f3f3f3f;
int n, m;
int d[maxn][maxn];
vector<int> g[maxn];
vector<pair<int, int> > dis[maxn], rdis[maxn];
void bfs() {
  for (int i = 1; i <= n; i++) {
    queue<int> que;
    que.push(i);
    while (!que.empty()) {
      int u = que.front();
      que.pop();
      for (auto v : g[u]) {
        if (d[i][v] != INF) continue;
        d[i][v] = d[i][u] + 1;
        que.push(v);
      }
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  memset(d, 0x3f, sizeof(d));
  for (int i = 1; i <= n; i++) d[i][i] = 0;
  bfs();
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (i != j) {
        if (d[i][j] < INF) dis[i].push_back(make_pair(d[i][j], j));
        if (d[j][i] < INF) rdis[i].push_back(make_pair(d[j][i], j));
      }
    sort(dis[i].begin(), dis[i].end());
    reverse(dis[i].begin(), dis[i].end());
    sort(rdis[i].begin(), rdis[i].end());
    reverse(rdis[i].begin(), rdis[i].end());
  }
  int maxx = 0, res;
  int r1, r2, r3, r4;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++)
      if (i != j && d[i][j] < INF) {
        for (int k = 0; k < 3 && k < rdis[i].size(); k++)
          if (rdis[i][k].second != j) {
            for (int x = 0; x < 3 && x < dis[j].size(); x++)
              if (dis[j][x].second != i) {
                if (rdis[i][k].second == dis[j][x].second) continue;
                res = rdis[i][k].first + d[i][j] + dis[j][x].first;
                if (res > maxx) {
                  maxx = res;
                  r1 = rdis[i][k].second;
                  r2 = i;
                  r3 = j;
                  r4 = dis[j][x].second;
                }
              }
          }
      }
  }
  printf("%d %d %d %d\n", r1, r2, r3, r4);
  return 0;
}
