#include <bits/stdc++.h>
using namespace std;
vector<int> elist[3010];
vector<int> rev_elist[3010];
int vlist[3010][3];
int rev_vlist[3010][3];
int cost[3010][3010];
bool visit[3010];
queue<int> q;
int main() {
  int n, m, a, b;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    elist[a].push_back(b);
    rev_elist[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) visit[j] = false;
    q.push(i);
    visit[i] = true;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      vlist[i][2] = vlist[i][1];
      vlist[i][1] = vlist[i][0];
      vlist[i][0] = v;
      for (int j = 0; j < elist[v].size(); j++) {
        if (!visit[elist[v][j]]) {
          visit[elist[v][j]] = true;
          q.push(elist[v][j]);
          if (cost[i][elist[v][j]] == 0 ||
              cost[i][elist[v][j]] > cost[i][v] + 1) {
            cost[i][elist[v][j]] = cost[i][v] + 1;
          }
        }
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) visit[j] = false;
    q.push(i);
    visit[i] = true;
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      rev_vlist[i][2] = rev_vlist[i][1];
      rev_vlist[i][1] = rev_vlist[i][0];
      rev_vlist[i][0] = v;
      for (int j = 0; j < rev_elist[v].size(); j++) {
        if (!visit[rev_elist[v][j]]) {
          visit[rev_elist[v][j]] = true;
          q.push(rev_elist[v][j]);
        }
      }
    }
  }
  int max = 0, max1 = 0, max2 = 0, max3 = 0, max4 = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (cost[i][j] == 0) continue;
      for (int k = 0; k < 3; k++) {
        if (rev_vlist[i][k] == j || rev_vlist[i][k] == i) continue;
        if (cost[rev_vlist[i][k]][i] == 0) continue;
        for (int l = 0; l < 3; l++) {
          if (vlist[j][l] == i || vlist[j][l] == j ||
              vlist[j][l] == rev_vlist[i][k])
            continue;
          if (cost[j][vlist[j][l]] == 0) continue;
          if (max <
              cost[rev_vlist[i][k]][i] + cost[i][j] + cost[j][vlist[j][l]]) {
            max = cost[rev_vlist[i][k]][i] + cost[i][j] + cost[j][vlist[j][l]];
            max1 = rev_vlist[i][k];
            max2 = i;
            max3 = j;
            max4 = vlist[j][l];
          }
        }
      }
    }
  }
  cout << max1 << " " << max2 << " " << max3 << " " << max4 << endl;
}
