#include <bits/stdc++.h>
using namespace std;
vector<int> a[3001];
vector<int> g[3001];
int dis[3001][3001];
int vis[3001];
queue<pair<int, int> > q;
vector<pair<int, int> > shi[3001];
vector<pair<int, int> > dan[3001];
void dfs(int s) {
  q.push(make_pair(s, 0));
  vis[s] = 1;
  while (!q.empty()) {
    pair<int, int> f = q.front();
    q.pop();
    for (long long k = 0; k < a[f.first].size(); k++)
      if (vis[a[f.first][k]] != 1) {
        q.push(make_pair(a[f.first][k], f.second + 1));
        g[s].push_back(a[f.first][k]);
        dan[s].push_back(make_pair(f.second + 1, a[f.first][k]));
        shi[a[f.first][k]].push_back(make_pair(f.second + 1, s));
        vis[a[f.first][k]] = 1;
        dis[s][a[f.first][k]] = f.second + 1;
      }
  }
}
bool gans(int x, int y, int z, int t) {
  if (x == y) return false;
  if (x == z) return false;
  if (x == t) return false;
  if (y == z) return false;
  if (y == t) return false;
  if (z == t) return false;
  return true;
}
int main() {
  int n, m;
  cin >> n >> m;
  int x, y;
  for (long long k = 0; k < m; k++) {
    cin >> x >> y;
    a[x].push_back(y);
  }
  int a1, a2, a3, a4;
  for (long long k = 1; k < n + 1; k++) {
    dfs(k);
    for (long long z = 1; z < n + 1; z++) vis[z] = 0;
  }
  for (long long k = 1; k < n + 1; k++) {
    sort(shi[k].begin(), shi[k].end());
    sort(dan[k].begin(), dan[k].end());
  }
  int maxing = 0;
  for (long long k = 1; k < n; k++) {
    for (long long j = 0; j < g[k].size(); j++) {
      int mt = 0;
      for (int i = shi[k].size() - 1; i >= 0; i--) {
        if (mt == 4) break;
        int mt2 = 0;
        for (int t = dan[g[k][j]].size() - 1; t >= 0; t--) {
          if (mt2 == 4) break;
          if (gans(shi[k][i].second, dan[g[k][j]][t].second, k, g[k][j])) {
            int s = shi[k][i].first + dis[k][g[k][j]] + dan[g[k][j]][t].first;
            if (s > maxing) {
              maxing = s;
              a1 = shi[k][i].second;
              a2 = k;
              a3 = g[k][j];
              a4 = dan[g[k][j]][t].second;
            }
          }
          mt2++;
        }
        mt++;
      }
    }
  }
  cout << a1 << " " << a2 << " " << a3 << " " << a4;
  return 0;
}
