/* This is the solution to this problem: 
   https://codeforces.com/group/KIrM1Owd8u/contest/268794/problem/A
   It illustrates how to read in a graph and how to do a DFS.
*/

#include <bits/stdc++.h>
using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;

int n, m; vvi G;
vector<bool> visited;
vi visits;

void dfs(int u) {
  visited[u] = true;
  visits.push_back(u);

  for (auto &v : G[u]) {
    if (!visited[v]) dfs(v);
  }
}

int main(void) {
  cin >> n >> m;
  G = vvi(n, vi(0));
  for (int i = 0; i < m; i++) {
    int u, v; cin >> u >> v; u--; v--;
    G[u].push_back(v); G[v].push_back(u);
  }

  int count = 0;
  visited = vector<bool>(n, false);
  for (int u = 0; u < n; u++) {
    visits = vi(0);
    if (!visited[u]) {
      dfs(u);
      bool isCycle = true;
      for (auto &u : visits) isCycle = isCycle && G[u].size() == 2;
      count += isCycle;
    }
  }
  cout << count;

  return 0;
}