#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > al(200010);
vector<int> cc(200010);
bitset<200010> visited, cccycle;
void dfs(int u, int ccnum) {
  if (visited[u]) return;
  visited[u] = 1;
  cc[u] = ccnum;
  for (auto v : al[u]) {
    dfs(v, ccnum);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    v--;
    u--;
    cin >> u >> v;
    al[u].push_back(v);
    al[v].push_back(u);
  }
  visited.reset();
  cccycle.set();
  int ccnum = 0;
  for (int u = 0; u < n; u++) {
    if (!visited[u]) dfs(u, ccnum++);
    if (al[u].size() != 2) cccycle[cc[u]] = 0;
  }
  int ans = 0;
  for (int i = 0; i < ccnum; i++) {
    if (cccycle[i]) ans++;
  }
  cout << ans;
  return 0;
}
