#include <bits/stdc++.h>
using namespace std;
bool is_digit(char x) { return ('0' <= x && x <= '9'); }
bool is_upper(char x) { return ('A' <= x && x <= 'Z'); }
bool is_lower(char x) { return ('a' <= x && x <= 'z'); }
int gcd(int a, int b) { return a ? gcd(b % a, a) : b; }
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const int N = 2e5 + 123;
const long long inf = 1e18;
const long long mod = 1e9 + 7;
const string abc = "abcdefghijklmnopqrstuvwxyz";
const string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int n, m, ans = 0;
string s;
vector<int> g[N], d;
bool used[N], flag;
void dfs(int v) {
  used[v] = true;
  d.push_back(v);
  for (auto i : g[v])
    if (!used[i]) dfs(i);
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  for (int i = 0; i < n; ++i) {
    flag = 1;
    if (!used[i]) {
      d.clear();
      dfs(i);
      for (auto j : d)
        if (g[j].size() != 2) {
          flag = 0;
          break;
        }
      if (flag) ++ans;
    }
  }
  cout << ans;
  return 0;
}
