#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wmissing-declarations"
int const maxn = 3004;
short int dist[maxn][maxn];
vector<int> gr[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    gr[x].emplace_back(y);
  }
  int const inf = 3000;
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) dist[i][j] = inf;
    dist[i][i] = 0;
    queue<int> q;
    q.push(i);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (int x : gr[v]) {
        if (dist[i][x] == inf) {
          dist[i][x] = dist[i][v] + 1;
          q.push(x);
        }
      }
    }
  }
  int const maxcnt = 5;
  vector<vector<int> > minsfrom(n + 1, vector<int>(maxcnt, 1));
  vector<vector<int> > minsto(n + 1, vector<int>(maxcnt, 1));
  for (int i = 1; i <= n; ++i) {
    for (int& x : minsfrom[i]) x = i;
    for (int& x : minsto[i]) x = i;
    for (int j = 1; j <= n; ++j) {
      if (dist[j][i] < inf) {
        int tmp = 0;
        while (tmp < maxcnt && dist[minsfrom[i][tmp]][i] >= dist[j][i]) ++tmp;
        for (int k = maxcnt - 1; k > tmp; --k)
          minsfrom[i][k] = minsfrom[i][k - 1];
        if (tmp < maxcnt) minsfrom[i][tmp] = j;
      }
      if (dist[i][j] < inf) {
        int tmp = 0;
        while (tmp < maxcnt && dist[i][minsto[i][tmp]] >= dist[i][j]) ++tmp;
        for (int k = maxcnt - 1; k > tmp; --k) minsto[i][k] = minsto[i][k - 1];
        if (tmp < maxcnt) minsto[i][tmp] = j;
      }
    }
  }
  int ans1, ans2, ans3, ans4;
  int best = 0;
  for (int x = 1; x <= n; ++x)
    for (int y = 1; y <= n; ++y) {
      for (int i = 0; i < maxcnt; ++i)
        for (int j = 0; j < maxcnt; ++j) {
          int u = minsfrom[x][i];
          int v = minsto[y][j];
          if (x != y && x != u && x != v && y != u && y != v && u != v) {
            if (dist[u][x] < inf && dist[x][y] < inf && dist[y][v] < inf) {
              int cur = dist[u][x] + dist[x][y] + dist[y][v];
              if (best < cur) {
                best = cur;
                tie(ans1, ans2, ans3, ans4) = make_tuple(u, x, y, v);
              }
            }
          }
        }
    }
  cout << ans1 << ' ' << ans2 << ' ' << ans3 << ' ' << ans4 << '\n';
}
