#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const double PI = acos(-1.0);
const double EPS = 1e-8;
const int MOD = 1e9 + 7;
template <typename T>
void cmin(T &x, T y) {
  if (y < x) x = y;
}
template <typename T>
void cmax(T &x, T y) {
  if (y > x) x = y;
}
long long qpow(long long x, long long n, long long mod = MOD) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * x % mod;
    x = x * x % mod;
    n >>= 1;
  }
  return res;
}
namespace Solver {
void InitOnce() {}
int n, m;
vector<int> G[200005];
int ind[200005];
bool vis[200005];
void Read() {
  int res = scanf("%d%d", &n, &m);
  if (res == -1) exit(0);
  for (int i = 1; i <= n; ++i) {
    vis[i] = 0;
    ind[i] = 0;
    G[i].clear();
  }
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    G[u].emplace_back(v);
    G[v].emplace_back(u);
    ++ind[v];
    ++ind[u];
  }
}
void dfs(int u) {
  vis[u] = 1;
  for (int &v : G[u]) {
    if (vis[v]) continue;
    dfs(v);
  }
}
void Solve() {
  for (int i = 1; i <= n; ++i) {
    if (vis[i] == 0 && ind[i] != 2) {
      dfs(i);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; ++i) {
    if (vis[i] == 0) {
      ++cnt;
      dfs(i);
    }
  }
  printf("%d\n", cnt);
}
}  // namespace Solver
int main() {
  Solver::InitOnce();
  while (true) {
    Solver::Read();
    Solver::Solve();
  }
  return 0;
}
