#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e14;
const long long TE3 = 1005;
const long long TE5 = 100005;
vector<pair<int, int> > e;
int g[4001][4001], d[4001];
int main() {
  ios::sync_with_stdio(false);
  int n, m, a, b, mini = 20000;
  cin >> n >> m;
  for (int i = (0); i < (m); ++i) {
    cin >> a >> b;
    e.push_back(make_pair(a - 1, b - 1));
    g[a - 1][b - 1] = 1;
    g[b - 1][a - 1] = 1;
  }
  for (int i = (0); i < (n); ++i) {
    for (int j = (0); j < (n); ++j) {
      d[i] += g[i][j];
    }
  }
  for (int i = (0); i < (m); ++i) {
    a = e[i].first;
    b = e[i].second;
    for (int j = (0); j < (n); ++j) {
      if (g[a][j] && g[b][j]) {
        mini = min(mini, d[a] + d[b] + d[j] - 6);
      }
    }
  }
  if (mini != 20000)
    cout << mini;
  else
    cout << "-1";
  return 0;
}
