#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 500;
vector<int> q;
bool vis[maxn];
vector<int> g[maxn];
int du[maxn];
void dfs(int n) {
  vis[n] = true;
  q.push_back(n);
  for (int i = 0; i < g[n].size(); i++) {
    int to = g[n][i];
    if (vis[to]) continue;
    dfs(to);
  }
}
int main() {
  int m, n, a, b;
  cin >> m >> n;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
    du[a]++;
    du[b]++;
  }
  for (int i = 1; i <= m; i++) {
    if (!vis[i]) {
      q.clear();
      dfs(i);
      bool flag = false;
      for (int j = 0; j < q.size() && !flag; j++) {
        if (du[q[j]] != 2) {
          flag = true;
        }
      }
      if (!flag) sum++;
    }
  }
  cout << sum << endl;
  return 0;
}
