#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> G[2][3100];
int distances[2][3100][3100];
int biggest[2][3100][4];
void compute(int v, bool anti) {
  deque<int> f;
  f.push_front(v);
  for (int i = 0; i < n; i++) distances[anti][v][i] = -1e9;
  distances[anti][v][v] = 0;
  while (f.size()) {
    int w = *f.begin();
    f.pop_front();
    for (auto s : G[anti][w]) {
      if (distances[anti][v][s] > -1e9) continue;
      distances[anti][v][s] = distances[anti][v][w] + 1;
      f.push_back(s);
    }
  }
}
void kbiggest(int v, bool anti) {
  priority_queue<pair<int, int>> f;
  for (int i = 0; i < n; i++) {
    if (i == v) continue;
    pair<int, int> p = {-distances[anti][v][i], i};
    f.push(p);
    if (f.size() > 4) f.pop();
  }
  for (int k = 4 - 1; k >= 0; k--) {
    auto a = f.top();
    f.pop();
    biggest[anti][v][k] = a.second;
  }
}
int main(void) {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    G[0][a].push_back(b);
    G[1][b].push_back(a);
  }
  for (int i = 0; i < n; i++) {
    compute(i, 0);
    compute(i, 1);
    kbiggest(i, 0);
    kbiggest(i, 1);
  }
  int mx = 0;
  int m[4] = {0, 0, 0, 0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (i == j) continue;
      for (int k = 0; k < 4; k++) {
        for (int l = 0; l < 4; l++) {
          int a = biggest[1][i][k];
          int b = biggest[0][j][l];
          if (a == b || distances[1][i][a] <= 0 || distances[0][j][b] <= 0 ||
              a == i || a == j || b == i || b == j)
            continue;
          int v = distances[0][a][i] + distances[0][i][j] + distances[0][j][b];
          if (v > mx) {
            mx = v;
            m[0] = a + 1;
            m[1] = i + 1;
            m[2] = j + 1;
            m[3] = b + 1;
          }
        }
      }
    }
  }
  printf("%d %d %d %d\n", m[0], m[1], m[2], m[3]);
}
