#include <bits/stdc++.h>
using namespace std;
const int NMAX = 2 * 1e5 + 2;
int n, m;
vector<int> voisins[NMAX];
bool vu[NMAX];
bool dfs(int noeud) {
  if (vu[noeud]) return true;
  vu[noeud] = true;
  int sz = voisins[noeud].size();
  bool ans = (sz == 2);
  for (int j = 0; j < sz; j++) {
    int voisin = voisins[noeud][j];
    ans = dfs(voisin) && ans;
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int a = 0; a < m; a++) {
    int u, v;
    cin >> u >> v;
    voisins[u].push_back(v);
    voisins[v].push_back(u);
  }
  int nbCycle = 0;
  for (int depart = 1; depart <= n; depart++) {
    if (!vu[depart] && dfs(depart)) {
      nbCycle++;
    }
  }
  cout << nbCycle << '\n';
}
