#include <bits/stdc++.h>
using namespace std;
class UnionFind {
 private:
  std::vector<int> disj;
  std::vector<int> rank;

 public:
  UnionFind(int n) : disj(n), rank(n) {
    for (int i = 0; i < n; ++i) {
      disj[i] = i;
      rank[i] = 0;
    }
  }
  int root(int x) {
    if (disj[x] == x) {
      return x;
    }
    return disj[x] = root(disj[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    if (rank[x] < rank[y]) {
      disj[x] = y;
    } else {
      disj[y] = x;
      if (rank[x] == rank[y]) {
        ++rank[x];
      }
    }
  }
  bool is_same_set(int x, int y) { return root(x) == root(y); }
};
const int N = 200100;
vector<int> edges[N];
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  UnionFind uf(n);
  for (int i = (int)(0); i < (int)(m); i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    edges[u].push_back(v);
    edges[v].push_back(u);
    uf.unite(u, v);
  }
  vector<int> vert(n), rem(n);
  for (int i = (int)(0); i < (int)(n); i++) {
    int r = uf.root(i);
    vert[r]++;
    rem[r]++;
    if (edges[i].size() == 2) {
      rem[r]--;
    }
  }
  int tot = 0;
  for (int i = (int)(0); i < (int)(n); i++) {
    if (vert[i] >= 3 && rem[i] == 0) tot++;
  }
  cout << tot << endl;
}
