#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
void Dfs1(int v, int c, const Graph& gr, vector<int>& color) {
  color[v] = c;
  for (int u : gr[v]) {
    if (color[u] == -1) {
      Dfs1(u, c, gr, color);
    }
  }
}
bool Dfs2(int v, int pv, int color_size, const Graph& gr, vector<char>& use,
          vector<int>& way) {
  use[v] = true;
  way.push_back(v);
  if (gr[v].size() != 2) {
    return false;
  }
  for (int u : gr[v]) {
    if (u == pv) {
      continue;
    }
    if (use[u]) {
      return color_size == way.size();
    }
    return Dfs2(u, v, color_size, gr, use, way);
  }
  way.pop_back();
  return false;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  Graph gr(N);
  for (int i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  vector<int> color(N, -1);
  int c = 0;
  for (int i = 0; i < N; ++i) {
    if (color[i] == -1) {
      Dfs1(i, c, gr, color);
      ++c;
    }
  }
  vector<int> start(c, -1), cnt(c, 0);
  for (int i = 0; i < N; ++i) {
    start[color[i]] = i;
    ++cnt[color[i]];
  }
  vector<char> use(N, false);
  int result = 0;
  for (int i = 0; i < c; ++i) {
    if (cnt[i] < 3) {
      continue;
    }
    vector<int> way;
    if (Dfs2(start[i], -1, cnt[i], gr, use, way)) {
      ++result;
    }
  }
  cout << result << '\n';
  return 0;
}
