#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long MOD) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
const int maxn = 3010;
const int maxm = 5010;
const int inf = INT_MAX;
vector<int> G[maxn];
int d[maxn][maxn], d4[maxn][4], rd4[maxn][4];
int n, m;
void bfs(int u) {
  queue<int> Q;
  Q.push(u);
  d[u][u] = 0;
  while (!Q.empty()) {
    int x = Q.front();
    Q.pop();
    for (int i = 0; i < G[x].size(); ++i) {
      int v = G[x][i];
      if (d[u][v] == inf) {
        d[u][v] = d[u][x] + 1;
        Q.push(v);
      }
    }
  }
}
void calc4(int u) {
  auto cmp = [u](int x, int y) {
    return d[u][x] > d[u][y] || (d[u][x] == d[u][y] && x > y);
  };
  set<int, decltype(cmp)> S(cmp);
  for (int v = 1; v < n + 1; ++v)
    if (v != u && d[u][v] != inf) {
      S.insert(v);
      while (S.size() > 4) {
        auto it = S.end();
        --it;
        S.erase(it);
      }
    }
  auto it = S.begin();
  int p = 0;
  while (p < 4 && it != S.end()) d4[u][p++] = *it++;
}
void rcalc4(int u) {
  auto cmp = [u](int x, int y) {
    return d[x][u] > d[y][u] || (d[x][u] == d[y][u] && x > y);
  };
  set<int, decltype(cmp)> S(cmp);
  for (int v = 1; v < n + 1; ++v)
    if (v != u && d[v][u] != inf) {
      S.insert(v);
      while (S.size() > 4) {
        auto it = S.end();
        --it;
        S.erase(it);
      }
    }
  auto it = S.begin();
  int p = 0;
  while (p < 4 && it != S.end()) rd4[u][p++] = *it++;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int d1, d2;
    scanf("%d%d", &d1, &d2);
    G[d1].push_back(d2);
  }
  for (int i = 0; i < n + 1; ++i)
    for (int j = 0; j < n + 1; ++j) d[i][j] = inf;
  for (int i = 1; i < n + 1; ++i) bfs(i);
  for (int i = 1; i < n + 1; ++i) {
    calc4(i);
    rcalc4(i);
  }
  int ans = 0;
  vector<int> vc;
  for (int i = 1; i < n + 1; ++i)
    for (int j = 1; j < n + 1; ++j)
      if (i != j && d[i][j] != inf) {
        for (int k = 0; k < 4; ++k)
          for (int t = 0; t < 4; ++t) {
            int d1 = rd4[i][k], d2 = d4[j][t];
            if (d1 != 0 && d2 != 0 && d1 != d2 && d1 != j && d2 != i) {
              int sum = d[d1][i] + d[i][j] + d[j][d2];
              if (sum > ans) {
                ans = sum;
                vc.clear();
                vc.push_back(d1);
                vc.push_back(i);
                vc.push_back(j);
                vc.push_back(d2);
              }
            }
          }
      }
  for (int c : vc) printf("%d ", c);
  printf("\n");
  return 0;
}
