#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  vector<vector<int> > frnd(n + 1, vector<int>(0));
  int tfrnd[n + 1], minfrnd = 3 * m;
  bool found = false;
  for (int i = 1; i <= n; i++) tfrnd[i] = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    frnd[a].push_back(b);
    tfrnd[a]++;
    frnd[b].push_back(a);
    tfrnd[b]++;
  }
  for (int i = 1; i <= n; i++) sort(frnd[i].begin(), frnd[i].end());
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < tfrnd[i]; j++) {
      if (frnd[i][j] < i)
        continue;
      else {
        int a = i, b = frnd[i][j];
        if (tfrnd[a] + tfrnd[b] - 2 > minfrnd) continue;
        int ctra = j + 1, ctrb = 0;
        while (ctra < tfrnd[a] && ctrb < tfrnd[b]) {
          if (frnd[a][ctra] > frnd[b][ctrb])
            ctrb++;
          else if (frnd[b][ctrb] > frnd[a][ctra])
            ctra++;
          else {
            int c = frnd[a][ctra];
            found = true;
            minfrnd = min(minfrnd, tfrnd[a] + tfrnd[b] + tfrnd[c] - 6);
            ctra++;
            ctrb++;
          }
        }
      }
    }
  }
  if (!found)
    printf("-1\n");
  else
    printf("%d\n", minfrnd);
  return 0;
}
