#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void c_p_c() {}
bool PowerTwo(long long x) { return x && (!(x & (x - 1))); }
void solve() {
  long long n;
  cin >> n;
  if (PowerTwo(n)) {
    cout << "-1\n";
    return;
  }
  if (n == 3) {
    cout << "2"
         << " "
         << "3"
         << " "
         << "1\n";
    return;
  }
  long long a[n];
  long long i;
  a[0] = 2;
  a[1] = 3;
  a[2] = 1;
  for (i = 4; i <= n - 1; i += 2) {
    a[i - 1] = i + 1;
    a[i] = i;
  }
  if (n % 2 == 0) {
    a[n - 1] = n;
  }
  for (i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
  cout << endl;
}
int32_t main() {
  c_p_c();
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  long long x, y;
  vector<long long> adj[51];
  long long maxi = INT_MIN;
  while (n--) {
    cin >> x >> y;
    adj[x].push_back(y);
    maxi = max(maxi, x);
  }
  long long i;
  for (i = 1; i <= maxi; i++) {
    sort(adj[i].begin(), adj[i].end());
  }
  long long label[51];
  long long j = 1;
  vector<pair<long long, long long> > g[51];
  for (i = maxi; i >= 1; i--) {
    if (adj[i].size() != 0) {
      long long start = j;
      for (auto &it : adj[i]) {
        label[j++] = it;
      }
      long long end = j;
      g[i].push_back({start, end - 1});
    }
  }
  long long k = label[m];
  long long co = 0;
  for (i = maxi; i >= 1; i--) {
    if (adj[i].size() != 0) {
      for (auto &it : g[i]) {
        if (m >= it.first && m <= it.second) {
          for (auto &it : adj[i]) {
            if (it == k) co++;
          }
        }
      }
    }
  }
  cout << co;
}
