#include <bits/stdc++.h>
using namespace std;
vector<int> G[3005];
vector<int> GT[3005];
vector<int> keeper[3005];
vector<int> keeperT[3005];
int vis[3005];
int cost[3005][3005];
int costT[3005][3005];
void bfs(int u, vector<int> (&G)[3005], vector<int> (&keepers)[3005],
         int cost[3005][3005]) {
  queue<pair<int, int> > q;
  q.push(pair<int, int>(u, 0));
  int m1, m2, m3;
  m1 = m2 = m3 = u;
  while (!q.empty()) {
    pair<int, int> cur = q.front();
    q.pop();
    if (vis[cur.first] == 1) continue;
    vis[cur.first] = 1;
    cost[u][cur.first] = cur.second;
    m1 = m2;
    m2 = m3;
    m3 = cur.first;
    for (int i = 0; i < G[cur.first].size(); i++) {
      if (vis[G[cur.first][i]] == 0)
        q.push(pair<int, int>(G[cur.first][i], cur.second + 1));
    }
  }
  keepers[u].push_back(m1);
  keepers[u].push_back(m2);
  keepers[u].push_back(m3);
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    GT[v].push_back(u);
  }
  for (int i = 1; i <= N; i++) {
    memset(vis, 0, sizeof(vis));
    bfs(i, G, keeper, cost);
    memset(vis, 0, sizeof(vis));
    bfs(i, GT, keeperT, costT);
  }
  int ans = 0;
  int aa, ab, ac, ad;
  for (int b = 1; b <= N; b++) {
    for (int c = 1; c <= N; c++) {
      if (b == c) continue;
      for (int ap = 0; ap < keeperT[b].size(); ap++) {
        for (int dp = 0; dp < keeper[c].size(); dp++) {
          int a, d;
          a = keeperT[b][ap];
          d = keeper[c][dp];
          if (a != b && a != c && a != d && b != c && b != d && c != d) {
            if (cost[a][b] + cost[b][c] + cost[c][d] > ans && cost[a][b] != 0 &&
                cost[b][c] != 0 && cost[b][c] != 0) {
              ans = cost[a][b] + cost[b][c] + cost[c][d];
              aa = a;
              ab = b;
              ac = c;
              ad = d;
            }
          }
        }
      }
    }
  }
  printf("%d %d %d %d\n", aa, ab, ac, ad);
  return 0;
}
