#include <bits/stdc++.h>
using namespace std;
const int UNDEF = -1;
template <typename T>
inline bool chkmax(T &a, T b) {
  return a < b ? a = b, true : false;
}
template <typename T>
inline bool chkmin(T &a, T b) {
  return a > b ? a = b, true : false;
}
const int INF = 1ULL << 28ULL;
const int MAXN = 3000 + 4;
unordered_set<int> g[2][MAXN];
int d[2][MAXN][MAXN];
vector<pair<int, int> > v[2][MAXN];
int n;
void bfs(int init, int r) {
  for (int x = 0; x < n; x++) {
    d[r][init][x] = INF;
  }
  queue<int> q;
  q.push(init);
  d[r][init][init] = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (auto &w : g[r][x]) {
      if (d[r][init][w] == INF) {
        d[r][init][w] = d[r][init][x] + 1;
        q.push(w);
      }
    }
  }
  for (int x = 0; x < n; x++) {
    if (x == init) continue;
    if (d[r][init][x] < INF) {
      v[r][init].push_back(make_pair(-d[r][init][x], x));
    }
  }
  sort(v[r][init].begin(), v[r][init].end());
}
int main() {
  ios_base::sync_with_stdio(false);
  int m;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    g[0][x].insert(y);
    g[1][y].insert(x);
  }
  for (int r = 0; r < 2; r++) {
    for (int init = 0; init < n; init++) {
      bfs(init, r);
    }
  }
  int final = 0;
  int vfinal[10];
  for (int x = 0; x < n; x++) {
    for (int y = 0; y < n; y++) {
      if (x == y) continue;
      if (d[0][x][y] >= INF) continue;
      vector<int> bs;
      for (auto &w : v[1][x]) {
        int val = w.second;
        if (val != x && val != y) {
          bs.push_back(val);
          if (bs.size() >= 2) break;
        }
      }
      vector<int> be;
      for (auto &w : v[0][y]) {
        int val = w.second;
        if (val != x && val != y) {
          be.push_back(val);
          if (be.size() >= 2) break;
        }
      }
      for (auto &s : bs) {
        for (auto &e : be) {
          if (s == e) continue;
          int ans = d[0][s][x] + d[0][x][y] + d[0][y][e];
          if (ans >= INF) continue;
          if (ans > final) {
            vfinal[0] = s;
            vfinal[1] = x;
            vfinal[2] = y;
            vfinal[3] = e;
            final = ans;
          }
        }
      }
    }
  }
  for (int i = 0; i < 4; i++) {
    vfinal[i]++;
  }
  printf("%d %d %d %d\n", vfinal[0], vfinal[1], vfinal[2], vfinal[3]);
}
