#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
int n, m;
vector<int> graph[3010];
int d[3010][3010];
bool vis[3010][3010];
int ans[4];
vector<pair<int, int> > d1[3002], d2[3002];
void bfs(int s) {
  queue<int> que;
  d[s][s] = 0;
  que.push(s);
  while (que.size()) {
    int num = que.front();
    que.pop();
    for (int i = 0; i < graph[num].size(); i++) {
      if (d[s][graph[num][i]] != INF) continue;
      d[s][graph[num][i]] = d[s][num] + 1;
      que.push(graph[num][i]);
    }
  }
}
void init() {
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (j == i) continue;
      if (d[i][j] != INF) d1[i].push_back(make_pair(d[i][j], j));
      if (d[j][i] != INF) d2[i].push_back(make_pair(d[j][i], j));
    }
    sort(d1[i].begin(), d1[i].end());
    reverse(d1[i].begin(), d1[i].end());
    sort(d2[i].begin(), d2[i].end());
    reverse(d2[i].begin(), d2[i].end());
  }
}
inline void search() {
  int tt = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i != j && d[i][j] != INF) {
        for (int q = 0; q < d2[i].size() && q < 3; q++) {
          if (d2[i][q].second != j && d2[i][q].second != i)
            for (int p = 0; p < d1[j].size() && p < 4; p++) {
              if (d1[j][p].second == i || d1[j][p].second == j ||
                  d1[j][p].second == d2[i][q].second)
                continue;
              int tr = d[i][j] + d1[j][p].first + d2[i][q].first;
              if (tr > tt)
                ans[0] = d2[i][q].second, ans[1] = i, ans[2] = j,
                ans[3] = d1[j][p].second, tt = tr;
            }
        }
      }
    }
  }
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    if (vis[x][y]) continue;
    if (x == y) continue;
    vis[x][y] = true;
    graph[x].push_back(y);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < n; j++) d[i][j] = INF;
  for (int i = 0; i < n; i++) bfs(i);
  init();
  search();
  cout << ans[0] + 1 << " " << ans[1] + 1 << " " << ans[2] + 1 << " "
       << ans[3] + 1 << endl;
  return 0;
}
