#include <bits/stdc++.h>
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long int exp(long long int x, long long int y) {
  long long int res = 1;
  x = x % 1000000007;
  while (y > 0) {
    if (y & 1) res = (res * x) % 1000000007;
    y = y >> 1;
    x = (x * x) % 1000000007;
  }
  return res;
}
using namespace std;
long long int f;
vector<vector<long long int>> v(200001);
vector<long long int> vis(200001);
void dfs(long long int x) {
  if (vis[x]) return;
  vis[x] = 1;
  if (v[x].size() != 2) f = 1;
  for (long long int j = 0; j < v[x].size(); j++) dfs(v[x][j]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  long long int n, m, x, y, ans = 0;
  cin >> n >> m;
  for (long long int i = 0; i < m; i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  for (long long int i = 1; i < n + 1; i++) {
    if (vis[i] == 0) {
      f = 0;
      dfs(i);
      if (f == 0) ans++;
    }
  }
  cout << ans;
  return 0;
}
