#include <iostream>
#include <map>
using namespace std;
int main() {
map <string,int> s;
map <string,int> w;
int n, m, a = 0,b = 0;
cin >> n >> m;
string word, sent;
while(cin >> word){
if(word.back() == ',')word.pop_back();
sent = sent + word;
if(word.back() == '.' or word.back() == '?' or word.back() == '!'){
word.pop_back();
sent.pop_back();
if((++s[sent]) == m)a++;
sent = "";
}
if((++w[word]) == n)b++;
}
cout << b << ' ' << a;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbWFpbigpIHsKCW1hcCA8c3RyaW5nLGludD4gczsKCW1hcCA8c3RyaW5nLGludD4gdzsKCWludCBuLCBtLCBhID0gMCxiID0gMDsKCWNpbiA+PiBuID4+IG07CglzdHJpbmcgd29yZCwgc2VudDsKCXdoaWxlKGNpbiA+PiB3b3JkKXsKCQlpZih3b3JkLmJhY2soKSA9PSAnLCcpd29yZC5wb3BfYmFjaygpOwoJCXNlbnQgPSBzZW50ICsgd29yZDsKCQlpZih3b3JkLmJhY2soKSA9PSAnLicgb3Igd29yZC5iYWNrKCkgPT0gJz8nIG9yIHdvcmQuYmFjaygpID09ICchJyl7CgkJCXdvcmQucG9wX2JhY2soKTsKCQkJc2VudC5wb3BfYmFjaygpOwoJCQlpZigoKytzW3NlbnRdKSA9PSBtKWErKzsKCQkJc2VudCA9ICIiOwoJCX0KCQlpZigoKyt3W3dvcmRdKSA9PSBuKWIrKzsKCX0KCWNvdXQgPDwgYiA8PCAnICcgPDwgYTsKfQ==