INF = 1.0 / 0.0

def used_edges(sink, pre_node)
  ans = []
  p = pre_node[sink]
  while p != nil
    v, i = p
    ans << $node[v][i]
    p = pre_node[v]
  end
  return ans
end

def min_cost_flow(source, sink, required_flow)
  res = 0
  loop do
    dist = Array.new($n){INF}
    dist[source] = 0
    pre_node = Array.new($n){nil}

    loop do
      updated = false
      $n.times{|v|
        next if dist[v] == INF
        $node[v].each_with_index{|edge, i|
          capacity, target, cost = edge[0..2]
          new_dist = dist[v] + cost
          if capacity > 0 &&  dist[target] > new_dist
            dist[target] = new_dist
            pre_node[target] = [v, i]
            updated = true
          end
        }
      }
      break if not updated
    end
    return res if dist[sink] == INF

    path = used_edges(sink, pre_node)

    aug = 1
    res += aug
    path.each{|e|
      target,idx = e[1], e[3]
      e[0] -= aug
      $node[target][idx][0] += aug
    }
  end
end

x, y, e = gets.split.map(&:to_i)

$n = x+y+2
$node = Array.new($n){[]}

x.times{|i|
  s = 0
  t = i+1
  ls = $node[s].size
  lt = $node[t].size
  $node[s] << [1, t, 0, lt]
  $node[t] << [0, s, 0, ls]
}

y.times{|i|
  s = i+x+1
  t = x+y+1
  ls = $node[s].size
  lt = $node[t].size
  $node[s] << [1, t, 0, lt]
  $node[t] << [0, s, 0, ls]
}


e.times{
  xi, yi = gets.split.map(&:to_i)
  s = xi + 1
  t = yi + x + 1
  ls = $node[s].size
  lt = $node[t].size
  $node[s] << [1, t, 1, lt]
  $node[t] << [0, s,-1, ls]
}

puts min_cost_flow(0, $n-1, e)