// inputに入力データ全体が入る
function Main(input) {
  input = input.split('\n');
  var answer;

  var good = []; 
  var bad = []; 
  var switched = false;
  var counts = {};
  var max = 0;
  // nums = nums.map((e) => parseInt(e));

  for (var i = 1; i < input.length; i++) {
    if (/\d/.test(input[i])) {
      switched = true;
      continue;
    }

    if (switched) {
      bad.push(input[i]);
    } else {
      good.push(input[i]);
    }
  }

  good.forEach(e => {
    if (counts[e]) {
      counts[e] += 1;
    } else {
      counts[e] = 1;
    }
  });

  bad.forEach(e => {
    if (counts[e]) {
      counts[e] -= 1;
    }
  });

  for (var key in counts) {
    if (counts[key] > max) {
      max = counts[key];
    }
  }



  // 出力
  console.log(max);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

