#include <bits/stdc++.h>
using namespace std;
void dfs(long long i, vector<vector<long long> > &G, vector<bool> &isVis,
         bool &x) {
  isVis[i] = true;
  if (G[i].size() != 2) {
    x = 0;
  }
  for (long long j = 0; j < G[i].size(); j++) {
    long long u = G[i][j];
    if (!isVis[u]) {
      dfs(u, G, isVis, x);
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<vector<long long> > G(n);
  for (long long i = 0; i < m; i++) {
    long long x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  vector<bool> isVis(n, 0);
  long long c = 0;
  for (long long i = 0; i < n; i++) {
    if (!isVis[i]) {
      bool x = 1;
      dfs(i, G, isVis, x);
      if (x) {
        c++;
      }
    }
  }
  cout << c << endl;
  return 0;
}
