#include <bits/stdc++.h>
using namespace std;
int n, m, u, v;
int dis[3003][3003];
pair<int, int> from[3003][3], to[3003][3];
vector<int> g[3003];
void bfs(int node) {
  queue<int> q;
  q.push(node);
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    for (int i = 0; i < g[cur].size(); i++) {
      int to = g[cur][i];
      if (to != node && !dis[node][to]) {
        dis[node][to] = dis[node][cur] + 1;
        q.push(to);
      }
    }
  }
}
int main() {
  scanf("%d", &n);
  scanf("%d", &m);
  while (m--) {
    scanf("%d", &u);
    scanf("%d", &v);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) {
    bfs(i);
    for (int j = 1; j <= n; j++) {
      if (dis[i][j]) {
        if (from[i][0].first < dis[i][j]) {
          from[i][2] = from[i][1];
          from[i][1] = from[i][0];
          from[i][0].first = dis[i][j];
          from[i][0].second = j;
        } else if (from[i][1].first < dis[i][j]) {
          from[i][2] = from[i][1];
          from[i][1].first = dis[i][j];
          from[i][1].second = j;
        } else if (from[i][2].first < dis[i][j]) {
          from[i][2].first = dis[i][j];
          from[i][2].second = j;
        }
        if (to[j][0].first < dis[i][j]) {
          to[j][2] = to[j][1];
          to[j][1] = to[j][0];
          to[j][0].first = dis[i][j];
          to[j][0].second = i;
        } else if (to[j][1].first < dis[i][j]) {
          to[j][2] = to[j][1];
          to[j][1].first = dis[i][j];
          to[j][1].second = i;
        } else if (to[j][2].first < dis[i][j]) {
          to[j][2].first = dis[i][j];
          to[j][2].second = i;
        }
      }
    }
  }
  int max_dis = 0, cur_dis;
  int res[4];
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (!dis[i][j]) continue;
      for (int o = 0; o < 3; o++) {
        for (int p = 0; p < 3; p++) {
          cur_dis = dis[i][j] + to[i][o].first + from[j][p].first;
          if (cur_dis > max_dis && to[i][o].second != j &&
              to[i][o].second != from[j][p].second && from[j][p].second != i &&
              to[i][o].second && from[j][p].second) {
            max_dis = cur_dis;
            res[0] = to[i][o].second;
            res[1] = i;
            res[2] = j;
            res[3] = from[j][p].second;
          }
        }
      }
    }
  }
  cout << res[0] << " " << res[1] << " " << res[2] << " " << res[3] << endl;
  return 0;
}
