#include <bits/stdc++.h>
using namespace std;
const int MX = 100000;
const long long MOD = 1000000007;
const int base = 131;
long long fast_exp(long long base, long long exp, long long mod) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base) % mod;
    base = (base * base) % mod;
    exp /= 2;
  }
  return res;
}
long long inv(long long a, long long m) { return fast_exp(a, m - 2, m); }
int a[4111][4111];
pair<int, int> v[4111];
int deg[4111];
int main() {
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0, _i = (m); i < _i; ++i) {
    cin >> v[i].first >> v[i].second;
    a[v[i].first][v[i].second] = a[v[i].second][v[i].first] = 1;
    ++deg[v[i].first];
    ++deg[v[i].second];
  }
  int mn = 1e8;
  for (int i = 0, _i = (m); i < _i; ++i) {
    for (int j = 1; j <= n; j++) {
      if (a[v[i].first][j] && a[v[i].second][j])
        mn = min(mn, deg[v[i].first] - 2 + deg[v[i].second] - 2 + deg[j] - 2);
    }
  }
  if (mn == 1e8)
    cout << "-1";
  else
    cout << mn;
  return 0;
}
