#include <bits/stdc++.h>
using namespace std;
template <typename T>
T in() {
  char ch;
  T n = 0;
  bool ng = false;
  while (1) {
    ch = getchar();
    if (ch == '-') {
      ng = true;
      ch = getchar();
      break;
    }
    if (ch >= '0' && ch <= '9') break;
  }
  while (1) {
    n = n * 10 + (ch - '0');
    ch = getchar();
    if (ch < '0' || ch > '9') break;
  }
  return (ng ? -n : n);
}
template <typename T>
inline T POW(T B, T P) {
  if (P == 0) return 1;
  if (P & 1)
    return B * POW(B, P - 1);
  else
    return (POW(B, P / 2) * POW(B, P / 2));
}
template <typename T>
inline T Gcd(T a, T b) {
  if (a < 0) return Gcd(-a, b);
  if (b < 0) return Gcd(a, -b);
  return (b == 0) ? a : Gcd(b, a % b);
}
template <typename T>
inline T Lcm(T a, T b) {
  if (a < 0) return Lcm(-a, b);
  if (b < 0) return Lcm(a, -b);
  return a * (b / Gcd(a, b));
}
long long Bigmod(long long base, long long power, long long MOD) {
  long long ret = 1;
  while (power) {
    if (power & 1) ret = (ret * base) % MOD;
    base = (base * base) % MOD;
    power >>= 1;
  }
  return ret;
}
bool isVowel(char ch) {
  ch = toupper(ch);
  if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E')
    return true;
  return false;
}
long long ModInverse(long long number, long long MOD) {
  return Bigmod(number, MOD - 2, MOD);
}
bool isConst(char ch) {
  if (isalpha(ch) && !isVowel(ch)) return true;
  return false;
}
int toInt(string s) {
  int sm;
  stringstream second(s);
  second >> sm;
  return sm;
}
bool vis[3005];
int D2[3005][3005];
vector<int> B[3002];
vector<int> Ase1[3003];
pair<int, int> P[3003];
void Solve1(int s, int n) {
  for (int i = 0; i <= 3000; i++) vis[i] = false;
  queue<int> Q;
  Q.push(s);
  D2[s][s] = 0;
  vis[s] = 1;
  while (Q.size()) {
    int U = Q.front();
    Q.pop();
    for (int i = 0; i < B[U].size(); i++) {
      int v = B[U][i];
      if (!vis[v]) {
        D2[s][v] = D2[s][U] + 1;
        Q.push(v);
        vis[v] = 1;
      }
    }
  }
  int id = 0;
  for (int i = 1; i <= n; i++) {
    P[id++] = make_pair(D2[s][i], i);
  }
  sort(P, P + id);
  for (int i = id - 1; i >= id - 4; i--) {
    Ase1[s].push_back(P[i].second);
  }
}
vector<int> A[3005];
vector<int> Ase[3003];
int D1[3005][3005];
void Solve(int s, int n) {
  for (int i = 0; i <= 3000; i++) vis[i] = false;
  queue<int> Q;
  Q.push(s);
  D1[s][s] = 0;
  vis[s] = 1;
  while (Q.size()) {
    int U = Q.front();
    Q.pop();
    for (int i = 0; i < A[U].size(); i++) {
      int v = A[U][i];
      if (!vis[v]) {
        D1[s][v] = D1[s][U] + 1;
        Q.push(v);
        vis[v] = 1;
      }
    }
  }
  int id = 0;
  for (int i = 1; i <= n; i++) {
    P[id++] = make_pair(D1[s][i], i);
  }
  sort(P, P + id);
  for (int i = id - 1; i >= id - 4; i--) {
    Ase[s].push_back(P[i].second);
  }
}
int aa[10];
long long int GLobal;
void Dekhi(int a, int b) {
  for (int i = 0; i < Ase[b].size(); i++) {
    for (int j = 0; j < Ase1[a].size(); j++) {
      int x, y;
      x = Ase[b][i];
      y = Ase1[a][j];
      if (x == y) continue;
      if (x == a || x == b) continue;
      if (y == a || y == b) continue;
      if (!D1[a][b]) continue;
      if (!D1[b][x]) continue;
      if (!D2[a][y]) continue;
      long long int cst = D1[a][b];
      cst += D2[a][y];
      cst += D1[b][x];
      if (cst > GLobal) {
        aa[0] = y;
        aa[1] = a;
        aa[2] = b;
        aa[3] = x;
        GLobal = cst;
      }
    }
  }
}
int main() {
  int n, m;
  n = in<int>(), m = in<int>();
  GLobal = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    a = in<int>(), b = in<int>();
    A[a].push_back(b);
    B[b].push_back(a);
  }
  for (int i = 1; i < n + 1; i++) {
    Solve(i, n);
    Solve1(i, n);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i == j) continue;
      if (D1[i][j] == -200000000) continue;
      Dekhi(i, j);
    }
  }
  for (int i = 0; i < 4; i++) {
    printf("%d ", aa[i]);
  }
  printf("\n");
  return 0;
}
