#include <bits/stdc++.h>
using namespace std;
int n, m, c[3333][3333], a[5];
vector<int> g[3333];
set<pair<int, int>, greater<pair<int, int>>> from[3333], to[3333];
bitset<3333> b;
void BFS(int s) {
  queue<int> q;
  b = 0;
  q.push(s);
  b[s] = 1;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    for (int v : g[u]) {
      if (b[v] == 0) {
        c[s][v] = c[s][u] + 1;
        b[v] = 1;
        q.push(v);
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    g[u].emplace_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 (c[i][j] > 0) {
        from[i].insert({c[i][j], j});
        if (from[i].size() > 4) {
          from[i].erase(--end(from[i]));
        }
      }
      if (c[j][i] > 0) {
        to[i].insert({c[j][i], j});
        if (to[i].size() > 4) {
          to[i].erase(--end(to[i]));
        }
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (c[i][j] > 0) {
        for (auto u : to[i]) {
          if (u.second != i && u.second != j) {
            for (auto v : from[j]) {
              if (v.second != i && v.second != j && v.second != u.second) {
                if (a[0] < u.first + c[i][j] + v.first) {
                  a[0] = u.first + c[i][j] + v.first;
                  a[1] = u.second;
                  a[2] = i;
                  a[3] = j;
                  a[4] = v.second;
                }
              }
            }
          }
        }
      }
    }
  }
  for (int i = 1; i <= 4; ++i) {
    cout << a[i] << " ";
  }
  return 0;
}
