#include <bits/stdc++.h>
using namespace std;
vector<int> gr[5005];
vector<int> gd[5005];
vector<int> q;
int r[5005][5005];
int d[5005][5005];
int farr[5005][2];
int fard[5005][2];
int indr[5005][2];
int indd[5005][2];
int ans, l;
int ind1, ind2, ind3, ind4;
void check(int A, int B, int C, int D) {
  if (!A || !D) return;
  if (A == C || B == D || A == D) return;
  if (d[A][B] == 5000) return;
  if (d[B][C] == 5000) return;
  if (d[C][D] == 5000) return;
  int ret = d[A][B] + d[B][C] + d[C][D];
  if (ret > ans) {
    ans = ret;
    ind1 = A;
    ind2 = B;
    ind3 = C;
    ind4 = D;
  }
}
int n, m, i, j, k, ii, jj, a, b;
int main() {
  cin >> n >> m;
  for (i = 1; i <= n; i++)
    for (j = i + 1; j <= n; j++) d[i][j] = d[j][i] = r[i][j] = r[j][i] = 5000;
  for (j = 1; j <= m; j++) {
    cin >> a >> b;
    gd[a].push_back(b);
    gr[b].push_back(a);
  }
  for (i = 1; i <= n; i++) {
    q.clear();
    q.push_back(i);
    l = 0;
    while (l < q.size()) {
      a = q[l];
      l++;
      for (j = 0; j < gd[a].size(); j++) {
        b = gd[a][j];
        if (d[i][b] > d[i][a] + 1) {
          d[i][b] = d[i][a] + 1;
          q.push_back(b);
        }
      }
    }
  }
  for (i = 1; i <= n; i++) {
    q.clear();
    q.push_back(i);
    l = 0;
    while (l < q.size()) {
      a = q[l];
      l++;
      for (j = 0; j < gr[a].size(); j++) {
        b = gr[a][j];
        if (r[i][b] > r[i][a] + 1) {
          r[i][b] = r[i][a] + 1;
          q.push_back(b);
        }
      }
    }
  }
  for (i = 1; i <= n; i++) {
    for (j = 1; j <= n; j++)
      if (d[i][j] != 5000 && d[i][j] > fard[i][0]) {
        fard[i][1] = fard[i][0];
        indd[i][1] = indd[i][0];
        fard[i][0] = d[i][j];
        indd[i][0] = j;
      } else if (d[i][j] != 5000 && d[i][j] > fard[i][1]) {
        fard[i][1] = d[i][j];
        indd[i][1] = j;
      }
  }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      if (r[i][j] != 5000 && r[i][j] > farr[i][0]) {
        farr[i][1] = farr[i][0];
        indr[i][1] = indr[i][0];
        farr[i][0] = r[i][j];
        indr[i][0] = j;
      } else if (r[i][j] != 5000 && r[i][j] > farr[i][1]) {
        farr[i][1] = r[i][j];
        indr[i][1] = j;
      }
  for (i = 1; i <= n; i++)
    for (j = 1; j <= n; j++)
      for (ii = 0; ii < 2; ii++)
        for (jj = 0; jj < 2; jj++)
          if (i != j) check(indr[i][ii], i, j, indd[j][jj]);
  cout << ind1 << " " << ind2 << " " << ind3 << " " << ind4 << endl;
}
