#include <bits/stdc++.h>
using namespace std;
const int N = 3 * 1e3 + 500;
int dis[N][N], n, m, k, u, a, d, anss, sum;
queue<int> q;
bool mark[N][N];
vector<int> nei[N], ans;
vector<pair<int, int> > s[N], w[N];
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int b;
    cin >> a >> b;
    a--, b--;
    nei[a].push_back(b);
  }
  cerr << "khar" << endl;
  for (int j = 0; j < n; j++) {
    mark[j][j] = 1;
    q.push(j);
    dis[j][j] = 0;
    while (!q.empty()) {
      k = q.front();
      for (int i = 0; i < nei[k].size(); i++) {
        u = nei[k][i];
        if (!mark[j][u]) {
          dis[j][u] = dis[j][k] + 1;
          q.push(u);
          mark[j][u] = 1;
        }
      }
      q.pop();
    }
    for (int i = 0; i < n; i++) s[j].push_back({dis[j][i], i});
    sort(s[j].begin(), s[j].end());
  }
  cerr << "gav" << endl;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) w[i].push_back({dis[j][i], j});
    sort(w[i].begin(), w[i].end());
  }
  for (int b = 0; b < n; b++)
    for (int c = 0; c < n; c++)
      for (int i = n - 1; i > n - 4; i--)
        for (int j = n - 1; j > n - 4; j--) {
          a = w[b][i].second, d = s[c][j].second;
          if (mark[a][b] && mark[b][c] && mark[c][d] && a != b && a != c &&
              a != d && b != c && b != d && c != d) {
            sum = w[b][i].first + dis[b][c] + s[c][j].first;
            if (sum > anss) {
              anss = sum;
              ans.clear();
              ans.push_back(a);
              ans.push_back(b);
              ans.push_back(c);
              ans.push_back(d);
              cerr << "kande" << endl;
            }
          }
        }
  cerr << "an" << endl;
  for (int i = 0; i < 4; i++) cout << ans[i] + 1 << " ";
}
