#include <bits/stdc++.h>
using namespace std;
bitset<200001> used;
int N, M;
vector<vector<int> > Ary;
void DFS(int n, bool& sum) {
  if (used[n]) return;
  used[n] = true;
  if (Ary[n].size() != 2) sum = false;
  for (auto k : Ary[n]) DFS(k, sum);
}
int main() {
  cin >> N >> M;
  Ary.resize(N + 1);
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    Ary[a].push_back(b);
    Ary[b].push_back(a);
  }
  int R = 0;
  for (int i = 1; i <= N; i++) {
    if (!used[i]) {
      bool sum = true;
      DFS(i, sum);
      R += sum;
    }
  }
  cout << R << endl;
}
