#include <bits/stdc++.h>
using namespace std;
const int n = 2e5 + 6;
vector<int> v[n];
int vis[n], check;
void dfs(int f) {
  vis[f] = 1;
  int x, i, n = v[f].size();
  if (n != 2) check = 0;
  for (i = 0; i < n; i++) {
    x = v[f][i];
    if (vis[x] == -1) dfs(x);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  int n, m, ans = 0;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  memset(vis, -1, sizeof(vis));
  for (int i = 1; i <= n; i++) {
    if (vis[i] == -1) {
      check = 1;
      dfs(i);
      if (check == 1) {
        ans++;
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
