#include <bits/stdc++.h>
using namespace std;
const int manx = 3000 + 10;
int a, b, n, m, dis[manx][manx], di[manx], second;
pair<int, int> no[manx][4];
pair<int, int> rev[manx][4];
bool vis[manx][manx], vis_r[manx][manx];
vector<int> G[manx];
vector<int> R[manx];
queue<int> Q;
void Normal_BFS(int w) {
  Q.push(w);
  vis[w][w] = true;
  pair<int, int> f, s, t;
  while (!Q.empty()) {
    int first = Q.front();
    Q.pop();
    for (int k = 0; k < G[first].size(); k++) {
      int i = G[first][k];
      if (!vis[w][i]) {
        vis[w][i] = true;
        dis[w][i] = dis[w][first] + 1;
        f = s;
        s = t;
        t = make_pair(i, dis[w][i]);
        Q.push(i);
      }
    }
  }
  no[w][0] = f;
  no[w][1] = s;
  no[w][2] = t;
}
void Reverse_BFS(int w) {
  Q.push(w);
  vis_r[w][w] = true;
  di[w] = 0;
  pair<int, int> f, s, t;
  while (!Q.empty()) {
    int first = Q.front();
    Q.pop();
    for (int k = 0; k < R[first].size(); k++) {
      int i = R[first][k];
      if (!vis_r[w][i]) {
        vis_r[w][i] = true;
        di[i] = di[first] + 1;
        f = s;
        s = t;
        t = make_pair(i, di[i]);
        Q.push(i);
      }
    }
  }
  rev[w][0] = f;
  rev[w][1] = s;
  rev[w][2] = t;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    G[a].push_back(b);
    R[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    Normal_BFS(i);
    Reverse_BFS(i);
  }
  int res = 0, ans_1, ans_2, ans_3, ans_4, db, dd;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      int dc = dis[i][j];
      if (j == i || dc == 0) continue;
      for (int k = 0; k < 3; k++) {
        int db = rev[i][k].second;
        a = rev[i][k].first;
        if (a == j || db == 0) continue;
        for (int l = 0; l < 3; l++) {
          int dd = no[j][l].second;
          second = no[j][l].first;
          if (second == a || second == i || dd == 0) continue;
          if (res < dd + db + dc) {
            res = dd + db + dc;
            ans_1 = a;
            ans_2 = i;
            ans_3 = j;
            ans_4 = second;
          }
        }
      }
    }
  }
  cout << ans_1 << " " << ans_2 << " " << ans_3 << " " << ans_4;
}
