#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
vector<vector<int>> adjlist;
vector<bool> vist;
vector<int> connected;
void dfs(int node) {
  connected.push_back(node);
  vist[node] = 1;
  for (auto child : adjlist[node])
    if (!vist[child]) dfs(child);
}
int main() {
  fast();
  int n, m;
  cin >> n >> m;
  adjlist.resize(n + 1);
  vist.resize(n + 1);
  while (m--) {
    int v, u;
    cin >> v >> u;
    adjlist[v].push_back(u);
    adjlist[u].push_back(v);
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (!vist[i]) {
      connected.clear();
      dfs(i);
      bool is_cycle = true;
      for (auto i : connected)
        if (adjlist[i].size() != 2) {
          is_cycle = false;
          break;
        }
      if (is_cycle) ans++;
    }
  }
  cout << ans << "\n";
  return 0;
}
