#define DEBUG 0
#include <bits/stdc++.h>
#define loop(n) for (lint ngtkana_is_a_genius = 0; ngtkana_is_a_genius < lint(n); ngtkana_is_a_genius++)
#define rep(i, begin, end) for (lint i = lint(begin); (i) < lint(end); i++)
#define all(v) v.begin(), v.end()
#define rand(l, r) std::uniform_int_distribution<>(l, r)(mt)
using lint = long long;
auto mt = std::mt19937_64(std::random_device{}());
auto cmn = [](auto&& a, auto b){ if (a > b) {a = b; return true;} return false; };
auto cmx = [](auto&& a, auto b){ if (a < b) {a = b; return true;} return false; };
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
  do {\
    std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
    debug_impl(__VA_ARGS__);\
    std::cerr << std::noboolalpha;\
  } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
  { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
 os << "{";
  for (auto it = v.begin(); it != v.end(); it++)
    {os << (it != v.begin() ? "," : "") << *it;}
  return os << "}";
}

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& tuple_input_impl(std::istream& os, Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { (void)std::initializer_list<int>{((void)(os >> std::get< Inds >(tuple)), 0)...}; return os; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::istream& operator>> (std::istream& os, Tuple<Args...>& tuple)
  { return tuple_input_impl(os, tuple, std::index_sequence_for<Args...>()); }

template < template < typename ... > class Tuple,  typename... Args, std::size_t ... Inds, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& tuple_output_impl(std::ostream& os, const Tuple<Args...>& tuple, std::integer_sequence<std::size_t, Inds...>)
  { os << "("; (void)std::initializer_list<int>{((void)(os << (Inds > 0 ? "," : "") << std::get< Inds >(tuple)), 0)...}; return os << ")"; }
template < template < typename ... > class Tuple,  typename... Args, std::size_t = std::tuple_size< Tuple < Args ... > >::value >
std::ostream& operator<< (std::ostream& os, const Tuple<Args...>& tuple)
 { return tuple_output_impl(os, tuple, std::index_sequence_for<Args...>()); }

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int L, R, m;
  std::cin >> L >> R >> m;
  int n = L + R;
  int s = n, t = n + 1;
  int N = n + 2;
  std::vector<std::vector<std::pair<int,int>>> graph(N);
  auto insert = [&] (int i, int j) {
    graph.at(i).emplace_back(j, false);
  };
  loop(m) {
    int i, j; std::cin >> i >> j;
    j += L;
    insert(i,j);
  }
  rep(i,0,L) insert(s, i);
  rep(i,0,R) insert(L + i, t);
  #if DEBUG
    rep(i,0,N) {
      auto v = graph.at(i);
      debug(i,v);
    }
  #endif
  debug(graph);

  int ans = 0;
  while (true) {
    std::vector<int> aug;
    std::vector<int> ckd(N, false);
    auto dfs = [&] (auto&&dfs, int x, int p) -> bool {
      bool found = x == t;
      ckd.at(x) = true;
      for (auto&& e : graph.at(x)) {
        int y, flag; std::tie(y, flag) = e;
        if (flag || y == p || ckd.at(y)) continue;
        if (dfs(dfs, y, x)) {
          found = true;
          e.second = true;
          graph.at(y).emplace_back(x, false);
        }
      }
      if (found) {
        aug.emplace_back(x);
      }
      return found;
    };
    bool found = dfs(dfs, s, s);
    if (!found) break;
    ans++;
    debug(ans, graph, aug);
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 3332