#include <bits/stdc++.h>
using namespace std;
const int N = 3333;
const long long INF = 1e9 + 19;
int n, m;
vector<int> e[N];
int mn1[N][4];
int mn2[N][4];
int d[N][N];
void read() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    e[v].push_back(u);
  }
}
void solve() {
  memset(d, 63, sizeof(d));
  for (int st = 0; st < n; st++) {
    d[st][st] = 0;
    queue<int> q;
    q.push(st);
    while (!q.empty()) {
      int v = q.front();
      q.pop();
      for (auto u : e[v])
        if (d[st][u] > d[st][v] + 1) {
          d[st][u] = d[st][v] + 1;
          q.push(u);
        }
    }
  }
  memset(mn1, -1, sizeof(mn1));
  memset(mn2, -1, sizeof(mn2));
  int answer = -1;
  int ra, rb, rc, rd;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[i][j] < INF && i != j) {
        mn1[i][3] = j;
        for (int k = 2; k >= 0; k--) {
          assert(mn1[i][k + 1] != -1);
          if (mn1[i][k] == -1 || (d[i][mn1[i][k]] < d[i][mn1[i][k + 1]])) {
            swap(mn1[i][k], mn1[i][k + 1]);
          }
        }
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      if (d[j][i] < INF && i != j) {
        mn2[i][3] = j;
        for (int k = 2; k >= 0; k--) {
          assert(mn2[i][k + 1] != -1);
          if (mn2[i][k] == -1 || d[mn2[i][k]][i] < d[mn2[i][k + 1]][i])
            swap(mn2[i][k], mn2[i][k + 1]);
        }
      }
    }
  }
  for (int a = 0; a < n; a++)
    for (int b = 0; b < n; b++) {
      if (a == b || d[a][b] > INF) continue;
      for (int k = 0; k < 3; k++)
        for (int t = 0; t < 3; t++) {
          int v = mn2[a][k];
          int u = mn1[b][t];
          if (v == -1 || u == -1) continue;
          if (v == u || v == a || v == b) continue;
          if (a == b || a == u || b == u) continue;
          int res = d[v][a] + d[a][b] + d[b][u];
          assert(res < INF);
          if (res > answer) {
            answer = res;
            ra = v;
            rb = a;
            rc = b;
            rd = u;
          }
        }
    }
  printf("%d %d %d %d\n", ra + 1, rb + 1, rc + 1, rd + 1);
}
void stress() {}
int main() {
  if (1) {
    int k = 1;
    for (int tt = 0; tt < k; tt++) {
      read();
      solve();
    }
  } else {
    stress();
  }
  return 0;
}
