#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
inline void fill_dist(vector<vector<int> > &dist, vector<vector<int> > &v) {
  int n = v.size();
  for (int i = 0; i < n; ++i) {
    vector<char> was(n, 0);
    queue<pair<int, int> > q;
    q.push({0, i});
    while (q.size()) {
      int now = q.front().second;
      int l = q.front().first;
      q.pop();
      if (was[now]) {
        continue;
      }
      was[now] = true;
      dist[i][now] = l;
      for (auto j : v[now]) {
        q.push({l + 1, j});
      }
    }
  }
}
inline void fill_lol(vector<vector<pair<int, int> > > &lol,
                     vector<vector<int> > &dist) {
  for (int i = 0; i < lol.size(); ++i) {
    for (int j = 0; j < lol.size(); ++j) {
      lol[i].push_back({dist[i][j], j});
    }
    sort(lol[i].begin(), lol[i].end());
    reverse(lol[i].begin(), lol[i].end());
  }
}
inline bool check(int a1, int a2, int a3, int a4, vector<vector<int> > &dist) {
  if (a1 == a2 or a1 == a3 or a1 == a4) {
    return false;
  }
  if (a2 == a3 or a2 == a4) {
    return false;
  }
  if (a3 == a4) {
    return false;
  }
  if (dist[a1][a2] == -1 or dist[a2][a3] == -1 or dist[a3][a4] == -1) {
    return false;
  }
  return true;
}
inline void solve1() {
  int n, m;
  cin >> n >> m;
  vector<vector<int> > v1(n), v2(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    v1[a].push_back(b);
    v2[b].push_back(a);
  }
  vector<vector<int> > dist1(n, vector<int>(n, -1));
  vector<vector<int> > dist2(n, vector<int>(n, -1));
  fill_dist(dist1, v1);
  fill_dist(dist2, v2);
  vector<vector<pair<int, int> > > lol1(n), lol2(n);
  fill_lol(lol1, dist1), fill_lol(lol2, dist2);
  int a1, a2, a3, a4, ma = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      for (int k = 0; k < 3; ++k) {
        for (int h = 0; h < 3; ++h) {
          if (check(lol2[i][h].second, i, j, lol1[j][k].second, dist1)) {
            if (ma < dist1[lol2[i][h].second][i] + dist1[i][j] +
                         dist1[j][lol1[j][k].second]) {
              ma = dist1[lol2[i][h].second][i] + dist1[i][j] +
                   dist1[j][lol1[j][k].second];
              a1 = lol2[i][h].second;
              a2 = i;
              a3 = j;
              a4 = lol1[j][k].second;
            }
          }
        }
      }
    }
  }
  cout << a1 + 1 << ' ' << a2 + 1 << ' ' << a3 + 1 << ' ' << a4 + 1;
}
int main() {
  solve1();
  return 0;
}
