#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 5;
int n, m;
vector<int> g[maxn];
long long dis[maxn][maxn];
vector<pair<long long, long long> > from[maxn], to[maxn];
void bfs(int x) {
  queue<int> q;
  q.push(x);
  dis[x][x] = 0;
  while (!q.empty()) {
    int now = q.front();
    q.pop();
    for (int i : g[now]) {
      if (dis[x][i] == -1) {
        dis[x][i] = dis[x][now] + 1;
        q.push(i);
      }
    }
  }
}
int main() {
  memset(dis, -1, sizeof(dis));
  scanf("%d%d", &n, &m);
  for (int u, v, i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      from[i].push_back({dis[i][j], j});
      to[j].push_back({dis[i][j], i});
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(from[i].begin(), from[i].end(),
         greater<pair<long long, long long> >());
    sort(to[i].begin(), to[i].end(), greater<pair<long long, long long> >());
  }
  int a, b, c, d, cnt = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j || dis[i][j] == -1) continue;
      for (int k = 0; k < 4; k++) {
        if (to[i][k].second == j || to[i][k].second == i) continue;
        for (int l = 0; l < 4; l++) {
          if (from[j][l].second == i || from[j][l].second == to[i][k].second ||
              from[j][l].second == j)
            continue;
          if (to[i][k].first == -1 || from[j][l].first == -1) continue;
          long long now = dis[i][j] + to[i][k].first + from[j][l].first;
          if (now > cnt) {
            cnt = now;
            a = to[i][k].second, b = i, c = j, d = from[j][l].second;
          }
        }
      }
    }
  }
  printf("%d %d %d %d\n", a, b, c, d);
  return 0;
}
