#include <bits/stdc++.h>
const int maxVNr = 2e5;
using namespace std;
vector<int> adjLst[maxVNr];
int vis[maxVNr];
int clrCnt = 0;
bool pr_loop, pr_2adj;
void dfs(int v, int par) {
  vis[v] = 1;
  if (adjLst[v].size() != 2) pr_2adj = false;
  for (int i = 0; i < adjLst[v].size(); ++i) {
    if (vis[adjLst[v][i]] == 1 and adjLst[v][i] != par) {
      pr_loop = true;
    }
    if (vis[adjLst[v][i]] == 0) {
      dfs(adjLst[v][i], v);
    }
  }
  vis[v] = 2;
}
int main() {
  int u, v, nV, mE;
  cin >> nV >> mE;
  for (int i = 0; i < mE; ++i) {
    cin >> u >> v;
    u--;
    v--;
    adjLst[u].push_back(v);
    adjLst[v].push_back(u);
  }
  int res = 0;
  for (int i = 0; i < nV; ++i) {
    if (vis[i] == 0) {
      pr_loop = false;
      pr_2adj = true;
      dfs(i, -1);
      if (pr_2adj) res++;
    }
  }
  cout << res;
  return 0;
}
