#include <bits/stdc++.h>
using namespace std;
int n, m, k;
const int N = 1010;
int pins[N];
int fre[N][N];
vector<pair<int, int> > v;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, a, b; i <= n; ++i) {
    scanf("%d%d", &a, &b);
    pins[b]++;
    fre[b][a]++;
  }
  int beauty = 0, mx = 0;
  for (int i = 0, a, b; i < m; ++i) {
    scanf("%d%d", &a, &b);
    if (pins[b] > 0 && fre[b][a] > 0) {
      mx++;
      beauty++;
      pins[b]--;
      fre[b][a]--;
    } else
      v.push_back(make_pair(b, a));
  }
  for (int i = 0, a, b; i < v.size(); ++i) {
    a = v[i].first;
    b = v[i].second;
    if (pins[a] > 0) {
      mx++;
      pins[a]--;
    }
  }
  cout << mx << " " << beauty << endl;
}
