#include <bits/stdc++.h>
using namespace std;
int n, res, m, deg[100001 * 2];
vector<int> a[100001 * 2], comp;
bool check[100001 * 2];
void dfs(int u) {
  comp.push_back(u);
  check[u] = true;
  for (int i = 0; i < a[u].size(); i++) {
    int v = a[u][i];
    if (!check[v]) dfs(v);
  }
}
bool Check(vector<int> comp) {
  for (int i = 0; i < comp.size(); i++)
    if (deg[comp[i]] != 2) return false;
  return true;
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    a[u].push_back(v);
    a[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  for (int i = 1; i <= n; i++)
    if (!check[i]) {
      comp.clear();
      dfs(i);
      if (Check(comp)) res++;
    }
  cout << res;
  return 0;
}
