#include <bits/stdc++.h>
using namespace std;
bool ciclo;
void dps(long long pos, vector<vector<long long> >& vet, vector<bool>& flag,
         vector<long long>& cont) {
  flag[pos] = true;
  if (cont[pos] != 2) ciclo = false;
  for (long long i = 0; i < vet[pos].size(); i++) {
    if (!flag[vet[pos][i]]) dps(vet[pos][i], vet, flag, cont);
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<vector<long long> > vet(n + 1);
  vector<bool> flag(n + 1, false);
  vector<long long> cont(n + 1, 0);
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    vet[a].push_back(b);
    vet[b].push_back(a);
    cont[a]++;
    cont[b]++;
  }
  long long soma = 0;
  bool podesomar;
  for (long long i = 1; i <= n; i++) {
    podesomar = false;
    ciclo = true;
    if (!flag[i]) podesomar = true;
    dps(i, vet, flag, cont);
    if (ciclo and podesomar) soma++;
  }
  cout << soma << endl;
  return 0;
}
