#include <bits/stdc++.h>
using namespace std;
vector<int> par[4010];
pair<int, int> ver[4020];
bool f[4010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    par[a].push_back(b);
    par[b].push_back(a);
    if (a > b) swap(a, b);
    ver[i] = make_pair(a, b);
  }
  for (int i = 0; i < (n); i++) sort(par[i].begin(), par[i].end());
  int mi = 1 << 30;
  for (int i = 0; i < (m); i++) {
    int a = ver[i].first;
    int b = ver[i].second;
    for (int j = 0; j < (n); j++) {
      if (find(par[j].begin(), par[j].end(), a) != par[j].end()) {
        if (find(par[j].begin(), par[j].end(), b) != par[j].end()) {
          mi =
              min(mi, (int)(par[a].size() + par[b].size() + par[j].size() - 6));
        }
      }
    }
  }
  if (mi == 1 << 30) mi = -1;
  cout << mi << endl;
}
