#include <bits/stdc++.h>
using namespace std;
void print(const char* msg, ...);
int N, M;
int edges[300002];
bool visited[300002];
vector<int> used;
vector<vector<int>> g;
void walk(int ind) {
  visited[ind] = true;
  used.push_back(ind);
  for (int i = 0; i < g[ind].size(); i++) {
    if (visited[g[ind][i]] == false) walk(g[ind][i]);
  }
}
int main() {
  cin >> N >> M;
  g.assign(N, vector<int>());
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a -= 1;
    b -= 1;
    g[a].push_back(b);
    g[b].push_back(a);
    edges[a] += 1;
    edges[b] += 1;
  }
  int sol = 0;
  for (int i = 0; i < N; i++) {
    if (visited[i] == false) {
      used.clear();
      walk(i);
      bool ok = true;
      for (auto& el : used) {
        if (edges[el] != 2) ok = false;
      }
      if (ok) sol += 1;
    }
  }
  cout << sol << "\n";
  return 0;
}
void print(const char* msg, ...) {}
