#include <bits/stdc++.h>
using namespace std;
int clr[4007], flag = 0;
int a[4007][4007], n, prt[4007];
vector<pair<int, int> > vec;
vector<int> g[4007];
void ini(int n) {
  int i, j;
  for (i = 1; i <= n; i++) {
    clr[i] = 3;
    prt[i] = -1;
  }
  for (i = 0; i < n; i++) {
    for (j = 0; j < n; j++) a[i][j] = 0;
  }
}
void dfs(int src) {
  int i, p;
  clr[src] = 1;
  for (i = 0; i < g[src - 1].size(); i++) {
    p = g[src - 1][i];
    if (clr[p] == 3) {
      prt[p] = src;
      dfs(p);
    } else if (clr[p] == 1 && p != prt[src]) {
      vec.push_back(pair<int, int>(p, src));
    }
  }
  clr[src] = 2;
  return;
}
int main() {
  int m, i, u, v, j;
  cin >> n >> m;
  int degree[n + 4];
  for (i = 1; i < n + 4; i++) degree[i] = 0;
  ini(n);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    g[u - 1].push_back(v);
    g[v - 1].push_back(u);
    a[u - 1][v - 1] = 1;
    a[v - 1][u - 1] = 1;
    degree[u]++;
    degree[v]++;
  }
  for (i = 1; i <= n; i++) {
    if (clr[i] == 3) {
      dfs(i);
    }
  }
  int mn = 100000, frst, sec;
  int sz = vec.size();
  if (!sz)
    cout << -1;
  else {
    for (i = 0; i < sz; i++) {
      frst = vec[i].first;
      sec = vec[i].second;
      for (j = 0; j < n; j++) {
        if (a[j][frst - 1] && a[j][sec - 1]) {
          int second = degree[j + 1] - 2 + degree[frst] - 2 + degree[sec] - 2;
          if (second < mn) mn = second;
        }
      }
    }
    if (mn == 100000)
      cout << -1;
    else
      cout << mn;
  }
  return 0;
}
