#include <bits/stdc++.h>
using namespace std;
vector<int> adj[200005];
int i, n, m, k, a, siz[200005], parent[200005], d[200005];
bool visited[200005];
set<int> cc;
int fin(int x) { return (parent[x] == x) ? x : parent[x] = fin(parent[x]); }
void uni(int x, int y) {
  if (fin(x) != fin(y))
    siz[fin(x)] += siz[fin(y)], siz[fin(y)] = 0, parent[fin(y)] = fin(x);
}
void dfs(int i) {
  visited[i] = true;
  for (auto u : adj[i]) {
    if (visited[u] == false) {
      dfs(u);
    }
  }
}
int main() {
  int r, y;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    parent[i] = i;
    siz[i] = 1;
  }
  for (i = 1; i <= m; i++) {
    cin >> r >> y;
    ++d[r];
    ++d[y];
    uni(r, y);
    parent[fin(r)] = fin(y);
  }
  for (i = 1; i <= n; i++) {
    cc.insert(fin(i));
  }
  for (int i = 1; i <= n; i++) {
    if (cc.count(fin(i)) && d[i] != 2) {
      cc.erase(fin(i));
    } else {
      continue;
    }
  }
  cout << cc.size() << endl;
  return 0;
}
