#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:667772160")
template <class T1>
void deb(T1 e1) {
  cout << e1 << endl;
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << endl;
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << endl;
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << endl;
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << endl;
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << endl;
}
vector<int> graph[3000 + 7], ans;
pair<int, int> frwd[3000 + 7][4], backwd[3000 + 7][4];
int level[3000 + 7][3000 + 7];
void cal_frwd(int nd1, int nd2, int valu) {
  if (frwd[nd1][0].second < valu) {
    frwd[nd1][2] = frwd[nd1][1];
    frwd[nd1][1] = frwd[nd1][0];
    frwd[nd1][0] = make_pair(nd2, valu);
  } else if (frwd[nd1][1].second < valu) {
    frwd[nd1][2] = frwd[nd1][1];
    frwd[nd1][1] = make_pair(nd2, valu);
  } else if (frwd[nd1][2].second < valu)
    frwd[nd1][2] = make_pair(nd2, valu);
}
void cal_backwd(int nd1, int nd2, int valu) {
  if (backwd[nd1][0].second < valu) {
    backwd[nd1][2] = backwd[nd1][1];
    backwd[nd1][1] = backwd[nd1][0];
    backwd[nd1][0] = make_pair(nd2, valu);
  } else if (backwd[nd1][1].second < valu) {
    backwd[nd1][2] = backwd[nd1][1];
    backwd[nd1][1] = make_pair(nd2, valu);
  } else if (backwd[nd1][2].second < valu)
    backwd[nd1][2] = make_pair(nd2, valu);
}
void bfs(int s) {
  queue<int> q;
  int u, v;
  q.push(s);
  level[s][s] = 1;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    for (int i = 0; i < graph[u].size(); i++) {
      v = graph[u][i];
      if (level[s][v] == 0) {
        level[s][v] = level[s][u] + 1;
        cal_backwd(v, s, level[s][u]);
        cal_frwd(s, v, level[s][u]);
        q.push(v);
      }
    }
  }
}
void solve(int n) {
  int sum = 0, temp;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j or level[i][j] == 0) continue;
      for (int k = 0; k < 3; k++) {
        for (int l = 0; l < 3; l++) {
          if (backwd[i][k].second == 0 or frwd[j][l].second == 0 or
              backwd[i][k].first == j or frwd[j][l].first == i or
              backwd[i][k].first == frwd[j][l].first)
            continue;
          temp = level[i][j] + backwd[i][k].second + frwd[j][l].second;
          if (temp > sum) {
            sum = temp;
            ans.clear();
            ans.push_back(backwd[i][k].first);
            ans.push_back(i);
            ans.push_back(j);
            ans.push_back(frwd[j][l].first);
          }
        }
      }
    }
  }
}
int main() {
  int n, m, u, v;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &u, &v);
    graph[u].push_back(v);
  }
  for (int i = 1; i <= n; i++) bfs(i);
  solve(n);
  for (int i = 0; i < ans.size(); i++) {
    if (i) printf(" ");
    printf("%d", ans[i]);
  }
  printf("\n");
  return 0;
}
