#include <bits/stdc++.h>
using namespace std;
int v, e;
bool visited[(int)(1e5 * 2 + 10)] = {0};
vector<int> vi[(int)(1e5 * 2 + 10)];
int compoNo[(int)(1e5 * 2 + 10)] = {0};
set<int> diffCompo;
void dfs(int ele, int compo) {
  compoNo[ele] = compo;
  for (auto it = vi[ele].begin(); it != vi[ele].end(); ++it)
    if (!visited[*it]) {
      visited[*it] = 1;
      dfs(*it, compo);
    }
}
int main() {
  cin >> v >> e;
  for (int i = 1; i <= e; i++) {
    int x, y;
    cin >> x >> y;
    vi[x].push_back(y);
    vi[y].push_back(x);
  }
  bool notToConsider[(int)(1e5 * 2 + 10)] = {0};
  for (int i = 0; i <= (int)(1e5 * 2 + 10) - 1; i++) {
    if (vi[i].size() > 2 or vi[i].size() < 2) notToConsider[i] = 1;
  }
  int compo = 1;
  for (int i = 0; i <= (int)(1e5 * 2 + 10) - 1; i++) {
    if (vi[i].size() and !visited[i]) {
      compoNo[i] = compo;
      for (auto it = vi[i].begin(); it != vi[i].end(); ++it)
        if (!visited[*it]) {
          visited[*it] = 1;
          dfs(*it, compo);
        }
      compo++;
    }
  }
  --compo;
  for (int i = 1; i <= compo; i++) diffCompo.insert(i);
  for (int i = 0; i <= (int)(1e5 * 2 + 10) - 1; i++)
    if (notToConsider[i])
      if (diffCompo.find(compoNo[i]) != diffCompo.end())
        diffCompo.erase(diffCompo.find(compoNo[i]));
  cout << diffCompo.size() << "\n";
}
