#include <bits/stdc++.h>
using namespace std;
bool m1[4001][4001];
vector<pair<int, int> > v;
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  int freq[5000];
  memset(freq, 0, sizeof(freq));
  memset(m1, 0, sizeof(m1));
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    if (x > y) swap(x, y);
    v.push_back(make_pair(x, y));
    m1[x][y] = 1;
    freq[x]++;
    freq[y]++;
  }
  sort(v.begin(), v.end());
  bool f = false;
  int min1 = 9999999;
  for (int i = 0; i < m; i++) {
    for (int j = i + 1; j < m; j++) {
      if (v[j].first == v[i].first) {
        if (m1[v[i].second][v[j].second]) {
          min1 = min(min1, freq[v[j].first] + freq[v[i].second] +
                               freq[v[j].second] - 6);
          f = true;
        }
      } else
        break;
    }
  }
  if (f)
    cout << min1;
  else
    cout << "-1";
  return 0;
}
