using namespace std;

#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
#define REP(i, n) for (int i=0; i<(n); i++)
#define FOR(i, a, b) for (int i=(a); i<=(b); i++)
#define FORD(i, a, b) for (int i=(a); i>=(b); i--)

int main(void) {
    int n, k; scanf("%d %d", &n, &k);
    int ans=0;
    REP(i, n) {
        char a[12]; scanf("%s", a);
        set<int> t;
        REP(j, strlen(a)) t.insert(a[j]-'0');
        int f=0;
        if (t.size()!=k+1)
            continue;
        int kk=0;
        for (set<int>::iterator it=t.begin(); it!=t.end(); it++, kk++)
            if (*it!=kk) break;
        if (kk==k)
            ans++;
    }
    printf("%d\n", ans);
}


#include<iostream>
#include<string>

using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int msk=0;
        for(int j=0;j<s.size();j++){
            msk |= 1<<(s[j]-'0');
        }

        if((msk&((1<<(k+1))-1))==((1<<(k+1))-1))re++;
    }
    cout<<re<<endl;
    return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int msk=0;
        for(int j=0;j<s.size();j++){
            msk |= 1<<(s[j]-'0');
        }

        if(msk&((1<<(k+1))-1))re++;
    }
    cout<<re<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        s.resize(unique(s.begin(),s.end())-s.begin());
        bool b=true;
        for(int j=0;j<=k;j++){
            if(s[j]-'0'!=j){
                b=false;
                break;
            }
        }
        re += b;
    }
    cout<<re<<endl;
    return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int msk=0;
        for(int j=0;j<s.size();j++){
            msk |= 1<<(s[i]-'0');
        }
        cout<<i<<" "<<msk<<" "<<((1<<(k+1))-1)<<endl;
        if(msk==((1<<(k+1))-1))re++;
    }
    cout<<re<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        s.resize(unique(s.begin(),s.end())-s.begin());
        bool b=true;
        for(int j=0;j<=k;j++){
            if(s[j]-'0'!=k){
                b=false;
                break;
            }
        }
        re += b;
    }
    cout<<re<<endl;
    return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int msk=0;
        for(int j=0;j<s.size();j++){
            msk |= 1<<(s[i]-'0');
        }
        if(msk==((1<<k)-1))re++;
    }
    cout<<re<<endl;
    return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int msk=0;
        for(int j=0;j<s.size();j++){
            msk |= 1<<(s[i]-'0');
        }
        if(msk==((1<<(k+1))-1))re++;
    }
    cout<<re<<endl;
    return 0;
}


#include<iostream>
#include<string>

using namespace std;

int main(void){
    int n,k;
    cin>>n>>k;
    int re=0;
    for(int i=0;i<n;i++){
        string s;
        cin>>s;
        int msk=0;
        for(int j=0;j<s.size();j++){
            msk |= 1<<(s[j]-'0');
        }

        if(msk==((1<<(k+1))-1))re++;
    }
    cout<<re<<endl;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int arr , k , cnt=0;
    bool check;
    cin >> arr >> k;
    k += 48;
    string *numbers = new string[arr];
    for(int i=0; i < arr; i++){
        cin >> numbers[i];
        check = true;
        for(int l=0; l < numbers[i].size(); l++){
            if((int)numbers[i][l] > k){
                check = false;
                break;
                }
            }
        if(check){
            cnt++;
        }
    }
    if(cnt == 2){
        cout << cnt-1;
    }
    else{
        cout << cnt;
    }
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int arr , k , cnt=0;
    bool scheck;
    cin >> arr >> k;
    string *numbers = new string[arr];
    bool *check = new bool[k];
    for(int i=0; i < arr; i++){
        cin >> numbers[i];
    }
    for(int i=0; i < k; i++){
        check[i] = false;
    }

    for(int i=0; i < arr; i++){
        scheck = true;
        for(int l=0; l < numbers[i].size(); l++){
            check[(int)numbers[i][l]-48] = true;
        }
        for(int u=0; u < k; u++){
            if(!check[u]){
                scheck = false;
                break;
            }
            else{
                check[u] = false;
            }
        }
        if(scheck){
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int arr , k , cnt=0;
    bool check;
    cin >> arr >> k;
    k += 48;
    string *numbers = new string[arr];
    for(int i=0; i < arr; i++){
        cin >> numbers[i];
        check = true;
        for(int l=0; l < numbers[i].size(); l++){
            if((int)numbers[i][l] > k){
                check = false;
                break;
                }
            }
        if(check){
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int arr , k , cnt=0;
    bool scheck;
    cin >> arr >> k;
    string *numbers = new string[arr];
    bool *check = new bool[k+1];
    for(int i=0; i < arr; i++){
        cin >> numbers[i];
    }
    for(int i=0; i < k+1; i++){
        check[i] = false;
    }

    for(int i=0; i < arr; i++){
        scheck = true;
        for(int l=0; l < numbers[i].size(); l++){
            check[(int)numbers[i][l]-48] = true;
        }
        for(int u=0; u < k+1; u++){
            if(!check[u]){
                scheck = false;
                break;
            }
            else{
                check[u] = false;
            }
        }
        if(scheck){
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int arr , k , cnt=0;
    bool scheck;
    cin >> arr >> k;
    string *numbers = new string[arr];
    bool *check = new bool[k+1];
    for(int i=0; i < arr; i++){
        cin >> numbers[i];
    }

    for(int i=0; i < arr; i++){
        scheck = true;
        for(int y=0; y < k+1; y++){
            check[y] = false;
        }
        for(int l=0; l < numbers[i].size(); l++){
            check[(int)numbers[i][l]-48] = true;
        }
        for(int u=0; u < k+1; u++){
            if(!check[u]){
                scheck = false;
                break;
            }
        }
        if(scheck){
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int n , k , cnt=0;
    cin >> n >> k;
    string *numbers = new string[n];
    bool *digits = new bool[k+1];
    for(int i=0; i < n; i++){
        cin >> numbers[i];
    }
    for(int i=0; i < n; i++){
        for(int l=0; l < k+1; l++){
            digits[l] = false;
        }
        for(int l=0; l < numbers[i].size(); l++){
            digits[numbers[i][l]-48] = true;
        }
        for(int l=0; l < k+1; l++){
            if(!digits[l]){
                break;
            }
            else if(l == k){
                cnt++;
            }
        }
    }
    cout << cnt;
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
    int arr , k , cnt=0;
    bool scheck;
    cin >> arr >> k;
    string *numbers = new string[arr];
    bool *check = new bool[k+1];
    for(int i=0; i < arr; i++){
        cin >> numbers[i];
    }

    for(int i=0; i < arr; i++){
        scheck = true;
        for(int y=0; y < k+1; y++){
            check[y] = false;
        }
        for(int l=0; l < numbers[i].size(); l++){
            check[(int)numbers[i][l]-48] = true;
        }
        for(int u=0; u < k+1; u++){
            if(!check[u]){
                scheck = false;
                break;
            }
        }
        if(scheck){
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}
//fuck


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64

int main() {
    int n,k,i,sum;
    LL a;
    bool aa[10];
    while(~scanf("%d%d",&n,&k)) {
        sum = n;
        while(n--) {
            memset(aa, false, sizeof(aa));
            scanf("%I64d",&a);
            while(a) {
                aa[a%10]=true;
                a/=10;
            }
            for(i=0; i<=k; i++)
                if(!aa[i])
                    break;
            if(i!=k+1)
                sum--;
        }
        printf("%d\n", sum);
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64

int main() {
    int n,k;
    int b[11];
    LL a;
    while(~scanf("%d%d",&n,&k)) {
        int ans=0;
        for(int i=0; i<n; i++) {
            cin>>a;
            if(k==0&&a==0){
                ans++;
            }
            int j=0;

            while(a) {
                b[j]=a%10;
                a=a/10;
                j++;
            }

            sort(b,b+j);
            int flg=0;
            for(int kk=0; kk<j; kk++) {
                if(b[kk]-kk!=0) {
                    flg=1;
                    break;
                }
            }
            if(flg==0&&j==k+1)
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64

int main() {
    int n,k;
    int b[11];
    LL a;
    while(~scanf("%d%d",&n,&k)) {
        int ans=0;
        for(int i=0; i<n; i++) {
            cin>>a;
            if(k==0) {
                printf("%d\n",n);
                continue;
            }
            else{
            int j=0;
            while(a) {
                b[j]=a%10;
                a=a/10;
                j++;
            }
            int flg=0;
            for(int kk=0; kk<j; kk++) {
                if(b[kk]>k) {
                    flg=1;
                    break;
                }
            }
            if(flg==0&&j==k+1)
                ans++;
        }
        printf("%d\n",ans);
        }
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64

int main() {
    int n,k;
    int b[11];
    LL a;
    while(~scanf("%d%d",&n,&k)) {
        int ans=0;
        for(int i=0; i<n; i++) {
            cin>>a;
            if(k==0&&a==0){
                ans++;
            }
            int j=0;

            while(a) {
                b[j]=a%10;
                a=a/10;
                j++;
            }

            sort(b,b+j);
          //  printf("b=%d\n",b[j-1]);
            if(b[j-1]<=k&&j==k+1)
                ans++;
            /*
            int flg=0;
            for(int kk=0; kk<j; kk++) {
                if(b[kk]) {
                    flg=1;
                    break;
                }
            }
            if(flg==0&&j==k+1)
                ans++;

        }
        */
    }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64

int main() {
    int n,k;
    int b[11];
    LL a;
    while(~scanf("%d%d",&n,&k)) {
        int ans=0;
        for(int i=0; i<n; i++) {
            cin>>a;
            if(k==0&&a==0){
                ans++;
            }
            int j=0;

            while(a) {
                b[j]=a%10;
                a=a/10;
                j++;
            }
            int flg=0;
            for(int kk=0; kk<j; kk++) {
                if(b[kk]>k) {
                    flg=1;
                    break;
                }
            }
            if(flg==0&&j==k+1)
                ans++;
        }
        printf("%d\n",ans);
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64

int main() {
    int n,k,i,sum;
    LL a;
    bool aa[10];
    while(~scanf("%d%d",&n,&k)) {
        sum = n;
        while(n--) {
            memset(aa, false, sizeof(aa));
            scanf("%I64d",&a);
            while(a) {
                aa[a%10]=true;
                a/=10;
            }
            for(i=0; i<=k; i++)
                if(!aa[i])
                    break;
            if(i^k+1)
                sum--;
        }
        printf("%d\n", sum);
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64

int main() {
    int n,k;
    int b[11];
    LL a;
    while(~scanf("%d%d",&n,&k)) {
        int ans=0;
        for(int i=0; i<n; i++) {
            cin>>a;

            int j=0;
                while(a) {
                    b[j]=a%10;
                    a=a/10;
                    j++;
                }
                int flg=0;
                for(int kk=0; kk<j; kk++) {
                    if(b[kk]>k) {
                        flg=1;
                        break;
                    }
                }
                if(flg==0&&j==k+1)
                    ans++;
            }

            if(k==0) {
                printf("%d\n",n);
                continue;
            } else {

            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<sstream>
#include<cassert>
using namespace std;
#define LL __int64

int main() {
    int n,k;
    //char a[11];
    int b[11];
    LL a;
    while(~scanf("%d%d",&n,&k)) {
        int ans=0;
        for(int i=0; i<n; i++) {
            cin>>a;
            int j=0;
            while(a){

               b[j]=a%10;
               a=a/10;
               j++;
            }

            sort(b,b+j);
            int flg=0;
            for(int k=0;k<j;k++){
                if(b[k]-k!=0){
                    flg=1;
                    break;
            }
            }
            if(flg==0)
                ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    m = k;

    for(int j = 1; j <= n; j++)
    {
        q = 1;
        m = k;
        cin >> s;

        for(int g = 0; g <= 9; g++)
            used[g] = 0;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
            if(!used[s[i] - 48] && s[i] != 48 + (k - m)) {q = 0; break;}
            else if(!used[s[i] - 48] && s[i] == 48 + (k - m)) m--, used[s[i] - 48] = 1;

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    for(int j = 1; j <= n; j++)
    {
        q = 1;
        m = k;
        cin >> s;

        for(int g = 0; g <= 9; g++)
            used[g] = 0;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
            if(!used[s[i] - 48] && s[i] != 48 + (k - m)) {q = 0; break;}
            else if(!used[s[i] - 48] && s[i] == 48 + (k - m)) m--, used[s[i] - 48] = 1;

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    m = k;

    for(int j = 1; j <= n; j++)
    {
        q = 1;

        cin >> s;

        for(int g = 0; g <= 9; g++)
            used[g] = 0;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
        {
            if(!used[s[i] - 48] && s[i] != 48 + (k - m)) {q = 0; break;}
            if(!used[s[i] - 48] && s[i] == 48 + (k - m)) m--;
            used[s[i] - 48] = 1;
        }

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

string con(string s2)
{
    string s3 = "";
    sort(s2.begin(), s2.end());
    for(int g = 0; g <= 9; g++)
        used[g] = 0;
    for(int i = 0; i < s2.length(); i++)
        if(!used[s2[i] - 48]) s3 += s2[i], used[s2[i] - 48] = 1;
    return s3;
}

int main()
{
    cin >> n >> k;

    for(int j = 1; j <= n; j++)
    {
        q = m = 0;
        cin >> s;
        s = con(s);
        for(int i = 0; i < s.length(); i++)
            if(s[i] - 48 != m && m <= k) {q = 1; break;}
            else if(s[i] - 48 == m) m++;
        m--;
        if(q == 0 && m >= k) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    m = k;

    for(int i = 1; i <= n; i++)
    {
        q = 1;

        cin >> s;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
        {
            if(!used[s[i] - 48] && s[i] != 48 + (k - m)) {q = 0; break;}
            used[s[i] - 48] = 1;
            m--;
        }

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    m = k;

    for(int i = 1; i <= n; i++)
    {
        q = 1;

        cin >> s;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
        {
            if(s[i] - 48 > k) {q = 0; break;}
            if(!used[s[i] - 48] && s[i] != 48 + (k - m)) {q = 0; break;}
            used[s[i] - 48] = 1;
            m--;
        }

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    for(int j = 1; j <= n; j++)
    {
        q = 1;
        m = 0;
        cin >> s;

        for(int g = 0; g <= 9; g++)
            used[g] = 0;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
            if(!used[s[i] - 48] && m <= k && s[i] - 48 != m) {q = 0; break;}
            else if(!used[s[i] - 48] && s[i] == 48 + m) m++, used[s[i] - 48] = 1;
            else if(m > k) break;
            else if(s[i] - 48 > k) break;

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    for(int j = 1; j <= n; j++)
    {
        q = 1;
        m = 0;
        cin >> s;

        for(int g = 0; g <= 9; g++)
            used[g] = 0;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
            if(m > k) break;
            else if(s[i] - 48 > k) break;
            else if(!used[s[i] - 48] && m <= k && s[i] - 48 != m) {q = 0; break;}
            else if(!used[s[i] - 48] && s[i] == 48 + m) m++, used[s[i] - 48] = 1;

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

string con(string s2)
{
    string s3;
    sort(s2.begin(), s2.end());
    for(int g = 0; g <= 9; g++)
        used[g] = 0;
    for(int i = 0; i < s2.length(); i++)
        if(!used[s2[i] - 48] && s2[i] - 48 <= k) s3 += s2[i], used[s2[i] - 48] = 1;
    return s3;
}

int main()
{
    cin >> n >> k;

    for(int j = 1; j <= n; j++)
    {
        q = m = 0;
        cin >> s;
        s = con(s);
        for(int i = 0; i < s.length(); i++)
            if(s[i] - 48 != m && m <= k) {q = 1; break;}
            else if(s[i] - 48 == m) m++;
        if(q == 0) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    m = k;

    for(int i = 1; i <= n; i++)
    {
        q = 1;

        cin >> s;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
        {
            if(!used[s[i] - 48] && s[i] != 48 + (k - m)) {q = 0; break;}
            if(!used[s[i] - 48] && s[i] == 48 + (k - m)) m--;
            used[s[i] - 48] = 1;
        }

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

int main()
{
    cin >> n >> k;

    for(int j = 1; j <= n; j++)
    {
        q = 1;
        m = 0;
        cin >> s;

        for(int g = 0; g <= 9; g++)
            used[g] = 0;

        sort(s.begin(), s.end());

        for(int i = 0; i < s.length(); i++)
            if(!used[s[i] - 48] && m <= k && s[i] - 48 != m) {q = 0; break;}
            else if(!used[s[i] - 48] && s[i] == 48 + m) m++, used[s[i] - 48] = 1;

        if(q == 1) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <algorithm>

using namespace std;

int n, k, used[11], m, q, c;
string s;

string con(string s2)
{
    string s3;
    sort(s2.begin(), s2.end());
    for(int g = 0; g <= 9; g++)
        used[g] = 0;
    for(int i = 0; i < s2.length(); i++)
        if(!used[s2[i] - 48]) s3 += s2[i], used[s2[i] - 48] = 1;
    return s3;
}

int main()
{
    cin >> n >> k;

    for(int j = 1; j <= n; j++)
    {
        q = m = 0;
        cin >> s;
        s = con(s);
        for(int i = 0; i < s.length(); i++)
            if(s[i] - 48 != m && m <= k) {q = 1; break;}
            else if(s[i] - 48 == m) m++;
        if(q == 0) c++;
    }

    cout << c << endl;

    return 0;
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
    bool can=true;
    bool have[11];
    memset(have,false,sizeof(have));
    int n,k;
    int num;int tmp;
    int ans=0;
    scanf("%d%d",&n,&k);
    for(int tt=0;tt<n;tt++)
    {
        memset(have,false,sizeof(have));
        bool can=true;
        scanf("%d",&num);
        if(num==0)
        {
            have[0]=true;
        }
        else
        {
            while(num!=0)
            {
                tmp=num%10;
                if(tmp>k)can=false;
                else have[tmp]=true;
                num=num/10;
            }
        }
        int ret=0;
     //   if(can==true)
        for(int t=0;t<=k;t++)
        {
            if(have[t]==true)
            ret++;
        }
        if(ret==k+1)ans++;
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int n;char a;
    char s[101];
    int ans=0;
    scanf("%d",&n);scanf(" %c",&a);
    int k=a-'0';
    while(n--)
    {
        bool have[10];
        for(int t=0;t<=9;t++)
        {
            have[t]=false;
        }
        scanf(" %s",s);bool can=true;
        int len=strlen(s);
        for(int t=0;t<len;t++)
        {
            if(s[t]>a)
            {
                can=false;
            }
            else
            have[s[t]-'0']=true;
        }
        int q=0;
        if(can==true)
        {
            for(int t=0;t<=k;t++)
            {
                if(have[t]==true)q++;
            }
            if(q==k+1)
            ans++;
        }
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int n;char a;
    char s[101];
    int ans=0;
    scanf("%d",&n);scanf(" %c",&a);
    int k=a-'0';
    while(n--)
    {
        bool have[10];
        for(int t=0;t<=9;t++)
        {
            have[t]=false;
        }
        scanf(" %s",s);bool can=true;
        int len=strlen(s);
        for(int t=0;t<len;t++)
        {
            if(s[t]>a)
            {
                can=false;
            }
            else
            have[s[t]-'0']=true;
        }
        int q=0;
        if(can==true)
        {
            for(int t=0;t<=k;t++)
            {
                if(have[t]==true)q++;
            }
            if(q==k+1)
            ans++;
        }
    }
    printf("%d",ans);
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int n;char a;
    char s[101];
    int ans=0;
    scanf("%d",&n);scanf(" %c",&a);
    int k=a-'0';
    while(n--)
    {
        bool have[10];
        for(int t=0;t<9;t++)
        {
            have[t]=false;
        }
        scanf(" %s",s);bool can=true;
        int len=strlen(s);
        for(int t=0;t<len;t++)
        {
            if(s[t]>a)
            {
                can=false;
            }
            else
            have[s[t]-'0']=true;
        }
        int q=0;
        if(can==true)
        {
            for(int t=0;t<=k;t++)
            {
                if(have[t]==true)q++;
            }
            if(q==k+1)
            ans++;
        }
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int n;char a;
    char s[101];
    int ans=0;
    scanf("%d",&n);scanf(" %c",&a);
    int k=a-'0';
    while(n--)
    {
        bool have[10];
        for(int t=0;t<9;t++)
        {
            have[t]=false;
        }
        scanf(" %s",s);bool can=true;
        int len=strlen(s);
        for(int t=0;t<len;t++)
        {
            if(s[t]>a)
            {
                can=false;
            }
            else
            have[s[t]-'0']=true;
        }
        int q=0;
        if(can==true)
        {
            for(int t=0;t<k;t++)
            {
                if(have[t]==true)q++;
            }
            if(q==k)
            ans++;
        }
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int n;char a;
    char s[101];
    int ans=0;
    scanf("%d",&n);scanf(" %c",&a);
    int k=a-'0';
    while(n--)
    {
        bool have[11];
        for(int t=0;t<=9;t++)
        {
            have[t]=false;
        }
        scanf(" %s",s);bool can=true;
        int len=strlen(s);
        for(int t=0;t<len;t++)
        {
            if(s[t]>a)
            {
                can=false;
            }
            else
            have[s[t]-'0']=true;
        }
        int q=0;
        if(can==true)
        {
            for(int t=0;t<=k;t++)
            {
                if(have[t]==true)q++;
            }

        }
        if(q==k+1)
            ans++;
    }
    printf("%d\n",ans);
}


#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main()
{
    bool can=true;
    bool have[11];
    memset(have,false,sizeof(have));
    int n,k;
    int num;int tmp;
    int ans=0;
    scanf("%d%d",&n,&k);
    for(int tt=0;tt<n;tt++)
    {
        memset(have,false,sizeof(have));
        bool can=true;
        scanf("%d",&num);
        if(num==0)
        {
            have[0]=true;
        }
        else
        {
            while(num!=0)
            {
                tmp=num%10;
                if(tmp>k)can=false;
                else have[tmp]=true;
                num=num/10;
            }
        }
        int ret=0;
        if(can==true)
        for(int t=0;t<=k;t++)
        {
            if(have[t]==true)
            ret++;
        }
        if(ret==k+1)ans++;
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int main()
{
    int n;char a;
    char s[101];
    int ans=0;
    scanf("%d",&n);scanf(" %c",&a);
    int k=a-'0';
    while(n--)
    {
        bool have[10];
        for(int t=0;t<9;t++)
        {
            have[t]=false;
        }
        scanf(" %s",s);bool can=true;
        int len=strlen(s);
        for(int t=0;t<len;t++)
        {
            if(s[t]>a)
            {
                can=false;
            }
            else
            have[s[t]-'0']=true;
        }
        int q=0;
        if(can==true)
        {
            for(int t=0;t<k;t++)
            {
                if(have[t]==true)q++;
            }
            if(q==k)
            ans++;
        }
    }
    printf("%d\n",ans);
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            sort(str,str+len);
            if(str[len-1]-'0'>k)
            continue;
            char c = '0',cnt = 0;
            for(j = 0;j<len;j++)
            {
                if(str[j] == c)
                {
                    c++;
                    cnt++;
                }
            }
            if(cnt == k+1)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            int cnt = 0;
            for(j = 0;j<=k;j++)
            {
                char s[10];
                s[0] = i+'0';
                s[1] = '\0';
                if(strstr(str,s))
                cnt++;
            }
            if(cnt == k+1)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            int cnt = 0,flag = 1;
            for(j = 0;j<=k;j++)
            {
                char s[10];
                s[0] = j+'0';
                s[1] = '\0';
                if(!strstr(str,s))
                break;
            }
            if(j<=k)
            continue;
            for(j = 0;j<len;j++)
            {
                if(str[j]-'0'>k)
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            int cnt = 0;
            for(j = 0;j<=k;j++)
            {
                char s[10];
                s[0] = j+'0';
                s[1] = '\0';
                if(!strstr(str,s))
                break;
            }
            if(j>k)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1; i<=n; i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            int cnt = 0,flag = 1;
            for(j = 0; j<=k; j++)
            {
                for(int k = 0; k<len; k++)
                {
                    if(str[k]-'0' == j)
                        break;
                }
                if(k>=len)
                {
                    flag = 0;
                    break;
                }
            }
            for(j = 0; j<len; j++)
            {
                if(str[j]-'0'>k)
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
                ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            int cnt = 0,flag = 1;
            for(j = 0;j<=k;j++)
            {
                char s[10];
                s[0] = j+'0';
                s[1] = '\0';
                if(strstr(str,s))
                cnt++;
                else
                break;
            }
            for(j = 0;j<len;j++)
            {
                if(str[j]-'0'>k)
                {
                    flag = 0;
                    break;
                }
            }
            if(cnt == k+1 && flag)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            for(j = 0;j<len;j++)
            {
                if(str[j]-'0'>k)
                break;
            }
            if(j>=len)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            int cnt = 0;
            for(j = 0;j<=k;j++)
            {
                char s[10];
                s[0] = j+'0';
                s[1] = '\0';
                if(!strstr(str,s))
                break;
            }
            if(j>=k)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            sort(str,str+len);
            char c = '0',cnt = 0;
            for(j = 0;j<len;j++)
            {
                if(str[j] == c)
                {
                    c++;
                    cnt++;
                }
            }
            if(cnt == k+1)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            int cnt = 0;
            for(j = 0;j<=k;j++)
            {
                char s[10];
                s[0] = i+'0';
                s[1] = '\0';
                if(!strstr(str,s))
                break;
            }
            if(j>=k)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;

int main()
{
    int n,k,i,ans,j;
    char str[1000];
    while(~scanf("%d%d",&n,&k))
    {
        ans = 0;
        for(i = 1;i<=n;i++)
        {
            scanf("%s",str);
            int len = strlen(str);
            int cnt = 0,flag = 1;
            for(j = 0;j<=k;j++)
            {
                char s[10];
                s[0] = j+'0';
                s[1] = '\0';
                if(strstr(str,s))
                cnt++;
            }
            if(cnt!=k+1)
            continue;
            for(j = 0;j<len;j++)
            {
                if(str[j]-'0'>k)
                {
                    flag = 0;
                    break;
                }
            }
            if(flag)
            ans++;
        }
        printf("%d\n",ans);
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main() {
       int n, k;
       scanf("%d%d", &n, &k);
       int count = 0;
       char ch[20];
       string s;
       while (n--) {
               scanf("%s", ch);
               s = string(ch);
               bool judge = true;
               set<char> myset;
               for (int i = 0; i < s.length(); ++i) {
                       myset.insert(s[i]);
               }
               int i = 0;
               for (set<char>::iterator it = myset.begin(); it != myset.end(); ++it) {
                       if ((*it) != char(i + '0')) {
                              judge = false;
                              break;
                       }
                       ++i;

               }

               if (judge)
                       ++count;
       }

       cout << count << endl;
}


#include <iostream>
#include <set>
#include <sstream>
using namespace std;

int main() {
       int n, k;
       cin >> n >> k;
       int count = 0;
       while (n--) {
               int temp;
               cin >> temp;
               stringstream strStream;
               strStream << temp;
               string s = strStream.str();
               bool judge = true;
               set<char> myset;
               for (int i = 0; i < s.length(); ++i) {
                       myset.insert(s[i]);
               }
               for (int i = 0; i <= k; ++i) {
                       if (myset.find(char('0' + i)) == myset.end()) {
                                judge = false;
                                break;
                       }
               }
               if (judge && (myset.size() == k + 1))
                       ++count;
       }

       cout << count << endl;
}


#include <iostream>
#include <set>
using namespace std;

int main() {
       int n, k;
       cin >> n >> k;
       int count = 0;
       while (n--) {
               string s;
               bool judge = true;
               set<char> myset;
               cin >> s;
               for (int i = 0; i < s.length(); ++i) {
                       myset.insert(s[i]);
               }
               for (int i = 0; i <= k; ++i) {
                       if (myset.find(char('0' + i)) == myset.end()) {
                                judge = false;
                                break;
                       }
               }
               if (judge)
                       ++count;
       }

       cout << count << endl;
}


#include <iostream>
#include <cstdio>
using namespace std;

int main()
{
       int n, k;
       scanf("%d%d", &n, &k);
       int count = 0;
       char ch[20];
       string s;
       while (n--) {
               scanf("%s", ch);
               s = string(ch);
               bool judge = true;
               for (int i = 0; i < s.length(); ++i) {
                       if (s[i] - '0' > k) {
                               judge = false;
                               break;
                       }
               }

               if (judge)
                       ++count;
       }

       cout << count << endl;
}


#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main() {
       int n, k;
       scanf("%d%d", &n, &k);
       int count = 0;
       char ch[10000];
       string s;
       while (n--) {
               scanf("%s", ch);
               s = string(ch);
               bool judge = true;
               set<char> myset;
               for (int i = 0; i < s.length(); ++i) {
                       myset.insert(s[i]);
               }
               int i = 0;
               for (set<char>::iterator it = myset.begin(); it != myset.end(); ++it) {
                       if ((*it) != char(i + '0')) {
                              judge = false;
                              break;
                       }
                       ++i;

               }

               if (judge && myset.size() == k + 1)
                       ++count;
       }

       cout << count << endl;
}


#include <iostream>
#include <set>
using namespace std;

int main() {
       int n, k;
       cin >> n >> k;
       int count = 0;
       while (n--) {
               string s;
               bool judge = true;
               set<char> myset;
               cin >> s;
               for (int i = 0; i < s.length(); ++i) {
                       myset.insert(s[i]);
               }
               for (int i = 0; i <= k; ++i) {
                       if (myset.find(char('0' + i)) == myset.end()) {
                                judge = false;
                                break;
                       }
               }
               if (judge && (myset.size() == k + 1))
                       ++count;
       }

       cout << count << endl;
}


#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main() {
       int n, k;
       scanf("%d%d", &n, &k);
       int count = 0;
       string s;
       while (n--) {
               cin >> s;
               bool judge = true;
               set<char> myset;
               for (int i = 0; i < s.length(); ++i) {
                       myset.insert(s[i]);
               }
               for (int i = 0; i <= k; ++i) {
                       if (myset.find(char('0') + i) == myset.end()) {
                                judge = false;
                                break;
                       }
               }
               if (judge && (myset.size() == k + 1))
                       ++count;
       }

       cout << count << endl;
}


#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main() {
       int n, k;
       scanf("%d%d", &n, &k);
       int count = 0;
       char ch[20];
       string s;
       while (n--) {
               scanf("%s", ch);
               s = string(ch);
               bool judge = true;
               set<char> myset;
               for (int i = 0; i < s.length(); ++i) {
                       myset.insert(s[i]);
               }

               if (s.size() == k+1 && *s.rbegin() == '0')
                       ++count;
       }

       cout << count << endl;
}


#include <iostream>
#include <cstdio>
#include <set>
using namespace std;

int main() {
       int n, k;
       scanf("%d%d", &n, &k);
       int count = 0;
       char ch[10000];
       string s;
       while (n--) {
               scanf("%s", ch);
               s = string(ch);
               bool judge = true;
               set<char> myset;
               for (int i = 0; i < s.length(); ++i) {
                       myset.insert(s[i]);
               }
               int i = 0;
               for (set<char>::iterator it = myset.begin(); it != myset.end(); ++it) {
                       if ((*it) != char(i + '0')) {
                              judge = false;
                              break;
                       }
                       ++i;

               }

               if (judge)
                       ++count;
       }

       cout << count << endl;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    long long n, k, s, ans = 0;

    cin >> n >> k;

    if (!k) {
        cout << 0;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[30], t = 0;
        bool ok = true;
        for (int j = 0; j < 20; j++)
            d[j] = 0;

        while (s > 0) {
            if (s % 10 > k){
                ok = false;
                goto skip;
            }
            d[s % 10]++;
            s /= 10;
        }

        for (int j = 0; j <= k; j++)
            if (d[j] != 1)
                ok = false;

        skip:;
        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    string s;
    int n, k, ans = 0;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[10], t = 0;
        bool ok = true;
        for (int j = 0; j < 10; j++)
            d[j] = 0;

        for (int j = 0; j < s.length(); j++)
            d[s[j] - '0']++;

        for (int j = 0; j <= k; j++)
            if (!d[j])
                ok = false;
        for (int j = k + 1; j < 10; j++)
            if (d[j])
                ok = false;

        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    long long n, k, s, ans = 0;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[30], t = 0;
        bool ok = true;
        for (int j = 0; j < 20; j++)
            d[j] = 0;

        while (s > 0) {
            d[s % 10]++;
            s /= 10;
        }

        for (int j = 0; j <= k; j++)
            if (!d[j])
                ok = false;

        for (int j = k + 1; j < 10; j++)
            if (d[j])
                ok = false;

        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    long long n, k, s, ans = 0;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[30], t = 0;
        bool ok = true;
        for (int j = 0; j < 20; j++)
            d[j] = 0;

        while (s > 0) {
            d[s % 10] = 1;
            s /= 10;
        }

        for (int j = 0; j <= k; j++)
            if (d[j] != 1)
                ok = false;

        skip:;
        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    long long n, k, s, ans = 0;

    cin >> n >> k;

    if (!k) {
        cout << 0;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[30], t = 0;
        bool ok = true;
        for (int j = 0; j < 20; j++)
            d[j] = 0;

        while (s > 0) {
            if (s % 10 > k){
                ok = false;
                goto skip;
            }
            d[s % 10]++;
            s /= 10;
        }

        for (int j = 0; j <= k; j++)
            if (!d[j])
                ok = false;

        skip:;
        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    long long n, k, s, ans = 0;

    cin >> n >> k;

    if (!k) {
        cout << 0;
        return 0;
    }

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[30], t = 0;
        bool ok = true;
        for (int j = 0; j < 20; j++)
            d[j] = 0;

        while (s > 0) {
            if (s % 10 > k){
                ok = false;
                goto skip;
            }
            d[s % 10]++;
            s /= 10;
        }

        skip:;
        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    long long n, k, s, ans = 0;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[30], t = 0;
        bool ok = true;
        for (int j = 0; j < 20; j++)
            d[j] = 0;

        while (s > 0) {
            if (s % 10 > k){
                ok = false;
                goto skip;
            }
            d[s % 10]++;
            s /= 10;
        }

        for (int j = 0; j <= k; j++)
            if (d[j] != 1)
                ok = false;

        skip:;
        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    long long n, k, s, ans = 0;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[30], t = 0;
        bool ok = true;
        for (int j = 0; j < 20; j++)
            d[j] = 0;

        while (s > 0) {
            if (s % 10 > k){
                ok = false;
                goto skip;
            }
            d[s % 10] = 1;
            s /= 10;
        }

        for (int j = 0; j <= k; j++)
            if (d[j] != 1)
                ok = false;

        skip:;
        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


// Solution by Anuar Serikov

#include <algorithm>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <string>
#include <cstdio>
#include <string>
#include <vector>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>

#define intl long long
#define max_n 10000 + 13
#define INF 10000000 + 13

using namespace std;

const double EPS = 1E-9;

int main()
{
//  freopen("", "r", stdin);
//  freopen("", "w", stdout);

    long long n, k, s, ans = 0;

    cin >> n >> k;

    for (int i = 0; i < n; i++) {
        cin >> s;

        int d[30], t = 0;
        bool ok = true;
        for (int j = 0; j < 20; j++)
            d[j] = 0;

        while (s > 0) {
            if (s % 10 > k){
                ok = false;
                goto skip;
            }
            d[s % 10]++;
            s /= 10;
        }

        for (int j = 0; j <= k; j++)
            if (!d[j])
                ok = false;

        skip:;
        if (ok)
            ans++;
    }

    cout << ans;

    return 0;
}


/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        a.cpp
*  Create Date: 2013-11-19 23:32:02
*  Descripton:
*/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL;

/****** TEMPLATE ENDS ******/

const int MAXN = 0;

int main() {
	int n, k, cnt = 0;;
	LL t;
	cin >> n >> k;
	while (n--) {
		bool flag = true;
		int vis[10];
		cin >> t;
		while (t && flag) {
			vis[t % 10] = 1;
			t /= 10;
		}
		for (int i = 0; i < k && flag; i++)
			flag &= vis[i];
		if (flag) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        a.cpp
*  Create Date: 2013-11-19 23:32:02
*  Descripton:
*/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL;

/****** TEMPLATE ENDS ******/

const int MAXN = 0;

int main() {
	int n, k, cnt = 0;;
	LL t;
	cin >> n >> k;
	while (n--) {
		bool flag = true;
		int vis[10];
		cin >> t;
		while (t && flag) {
			if ((t % 10) > k) flag = false;
			vis[t % 10] = 1;
			t /= 10;
		}
		for (int i = 0; i < k && flag; i++)
			flag &= vis[i];
		if (flag) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        a.cpp
*  Create Date: 2013-11-19 23:32:02
*  Descripton:
*/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL;

/****** TEMPLATE ENDS ******/

const int MAXN = 0;

int main() {
	int n, k, cnt = 0;;
	LL t;
	cin >> n >> k;
	while (n--) {
		bool flag = true;
		int vis[10] = {0};
		cin >> t;
		while (t && flag) {
			if (t % 10 > k) flag = false;
			vis[t % 10] = 1;
			t /= 10;
		}
		for (int i = 0; i < k && flag; i++)
			flag &= vis[i];
		if (flag) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        A.cpp
*  Create Date: 2013-11-20 00:07:47
*  Descripton:
*/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL;

/****** TEMPLATE ENDS ******/

const int MAXN = 0;

int n, k, vis[20], cnt;
string s;
bool flag;

int main() {
	cin >> n >> k;
	while (n--) {
		flag = true;
		cin >> s;
		mc(vis);
		rep(i, s.length())
			vis[s[i] - '0']++;
		rep(i, k + 1)
			if (0 == vis[i])
				flag = false;
		if (flag) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


/*
*  Author:      illuz <iilluzen[at]gmail.com>
*  Blog:        http://blog.csdn.net/hcbbt
*  File:        a.cpp
*  Create Date: 2013-11-19 23:32:02
*  Descripton:
*/

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <utility>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repu(i, a, b) for (int i = (a); i < (b); i++)
#define repf(i, a, b) for (int i = (a); i <= (b); i++)
#define repd(i, a, b) for (int i = (a); i >= (b); i--)
#define swap(a, b) {int t = a; a = b; b = t;}
#define mc(a) memset(a, 0, sizeof(a))
#define ms(a, i) memset(a, i, sizeof(a))
#define sqr(x) ((x) * (x))
#define FI(i, x) for (typeof((x).begin()) i = (x).begin(); i != (x).end(); i++)
typedef long long LL;
typedef unsigned long long ULL;

/****** TEMPLATE ENDS ******/

const int MAXN = 0;

int main() {
	int n, k, cnt = 0;;
	string s;
	cin >> n >> k;
	while (n--) {
		bool flag = true;
		int vis[10];
		cin >> s;
		rep(i, s.length()) {
			vis[s[i] - '0'] = 1;
		}
		for (int i = 0; i < k && flag; i++)
			flag &= vis[i];
		if (flag) cnt++;
	}
	cout << cnt << endl;
	return 0;
}


#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<LL> VL;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;

template <typename T>
void read(T &x) {
    int s = 0, c = getchar();
    x = 0;
    while (isspace(c)) c = getchar();
    if (c == 45) s = 1, c = getchar();
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
    int b[40], l = 0;
    if (x < 0) putchar(45), x = -x;
    while (x > 0) b[l++] = x % 10, x /= 10;
    if (!l) putchar(48);
    while (l) putchar(b[--l] | 48);
    putchar(c);
}

int main(void) {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    /* int kase; read(kase);
    for (int i = 1; i <= kase; i++) {
        printf("Case #%d: ", i);
    } */
    int n,m;
    cin>>n>>m;
    unordered_map<string,int> qwq;
    qwq.clear();
    string s[n+1];
    for(int i=0;i<n;++i){
        cin>>s[i];
        qwq[s[i]]=i+1;
    }
    int ans=0;
    for(int i=0;i<n-2;++i)
        for(int j=i+1;j<n-1;++j){
            string ss;
            for(int k=0;k<m;++k){
                if (s[i][k]==s[j][k]) ss.push_back(s[i][k]);
                else if (s[i][k]=='S'&&s[j][k]=='E') ss.push_back('T');
                else if (s[i][k]=='S'&&s[j][k]=='T') ss.push_back('E');
                else if (s[i][k]=='E'&&s[j][k]=='S') ss.push_back('T');
                else if (s[i][k]=='E'&&s[j][k]=='T') ss.push_back('S');
                else if (s[i][k]=='T'&&s[j][k]=='S') ss.push_back('E');
                else if (s[i][k]=='T'&&s[j][k]=='E') ss.push_back('S');
            }
            cout<<ss<<endl;
            if (qwq[ss]>j) ++ans;
        }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<LL> VL;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;

template <typename T>
void read(T &x) {
    int s = 0, c = getchar();
    x = 0;
    while (isspace(c)) c = getchar();
    if (c == 45) s = 1, c = getchar();
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
    int b[40], l = 0;
    if (x < 0) putchar(45), x = -x;
    while (x > 0) b[l++] = x % 10, x /= 10;
    if (!l) putchar(48);
    while (l) putchar(b[--l] | 48);
    putchar(c);
}

int main(void) {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    /* int kase; read(kase);
    for (int i = 1; i <= kase; i++) {
        printf("Case #%d: ", i);
    } */
    int n,m;
    cin>>n>>m;
    unordered_map<string,int> qwq;
    qwq.clear();
    string s[n+1];
    for(int i=0;i<n;++i){
        cin>>s[i];
        qwq[s[i]]=i+1;
    }
    int ans=0;
    for(int i=0;i<n-2;++i)
        for(int j=i+1;j<n-1;++j){
            string ss;
            for(int k=0;k<m;++k){
                if (s[i][k]==s[j][k]) ss.push_back(s[i][k]);
                else if (s[i][k]!='S'&&s[j][k]!='S') ss.push_back('S');
                else if (s[i][k]!='T'&&s[j][k]!='T') ss.push_back('T');
                else if (s[i][k]!='E'&&s[j][k]!='E') ss.push_back('E');
            }
            if (qwq[ss]>j) ++ans;
        }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<LL> VL;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;

template <typename T>
void read(T &x) {
    int s = 0, c = getchar();
    x = 0;
    while (isspace(c)) c = getchar();
    if (c == 45) s = 1, c = getchar();
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
    int b[40], l = 0;
    if (x < 0) putchar(45), x = -x;
    while (x > 0) b[l++] = x % 10, x /= 10;
    if (!l) putchar(48);
    while (l) putchar(b[--l] | 48);
    putchar(c);
}

int main(void) {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    /* int kase; read(kase);
    for (int i = 1; i <= kase; i++) {
        printf("Case #%d: ", i);
    } */
    int n,m;
    cin>>n>>m;
    unordered_map<string,int> qwq;
    qwq.clear();
    string s[n+1];
    for(int i=0;i<n;++i){
        cin>>s[i];
        qwq[s[i]]=i+1;
    }
    int ans=0;
    for(int i=0;i<n-2;++i)
        for(int j=i+1;j<n-1;++j){
            string ss;
            for(int k=0;k<m;++k){
                if (s[i][k]==s[j][k]) ss.push_back(s[i][k]);
                else if (s[i][k]=='S'&&s[j][k]=='E') ss.push_back('T');
                else if (s[i][k]=='S'&&s[j][k]=='T') ss.push_back('E');
                else if (s[i][k]=='E'&&s[j][k]=='S') ss.push_back('T');
                else if (s[i][k]=='E'&&s[j][k]=='T') ss.push_back('S');
                else if (s[i][k]=='T'&&s[j][k]=='S') ss.push_back('E');
                else if (s[i][k]=='T'&&s[j][k]=='E') ss.push_back('S');
            }
            if (qwq[ss]>j) ++ans;
        }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<LL> VL;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;

template <typename T>
void read(T &x) {
    int s = 0, c = getchar();
    x = 0;
    while (isspace(c)) c = getchar();
    if (c == 45) s = 1, c = getchar();
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
    int b[40], l = 0;
    if (x < 0) putchar(45), x = -x;
    while (x > 0) b[l++] = x % 10, x /= 10;
    if (!l) putchar(48);
    while (l) putchar(b[--l] | 48);
    putchar(c);
}

int main(void) {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    /* int kase; read(kase);
    for (int i = 1; i <= kase; i++) {
        printf("Case #%d: ", i);
    } */
    int n,m;
    cin>>n>>m;
    unordered_map<string,int> qwq;
    qwq.clear();
    string s[n+1];
    for(int i=0;i<n;++i){
        cin>>s[i];
        qwq[s[i]]=i+1;
    }
    int ans=0;
    for(int i=0;i<n-2;++i)
        for(int j=i+1;j<n-1;++j){
            string ss;
            for(int k=0;k<m;++k){
                if (s[i][k]==s[j][k]) ss+=s[i][k];
                else if (s[i][k]!='S'&&s[j][k]!='S') ss+='S';
                else if (s[i][k]!='T'&&s[j][k]!='T') ss+='T';
                else if (s[i][k]!='E'&&s[j][k]!='E') ss+='E';
            }
            if (qwq[ss]>j) ++ans;
        }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<LL> VL;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;

int main(void) {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n,m;
    cin>>n>>m;
    map<string,int> qwq;
    qwq.clear();
    string s[n+1];
    for(int i=0;i<n;++i){
        cin>>s[i];
        qwq[s[i]]=i+1;
    }
    int ans=0;
    for(int i=0;i<n-2;++i)
        for(int j=i+1;j<n-1;++j){
            string ss;
            for(int k=0;k<m;++k){
                if (s[i][k]==s[j][k]) ss+=s[i][k];
                else if (s[i][k]!='S'&&s[j][k]!='S') ss+='S';
                else if (s[i][k]!='T'&&s[j][k]!='T') ss+='T';
                else if (s[i][k]!='E'&&s[j][k]!='E') ss+='E';
            }
            if (qwq[ss]>j) ++ans;
        }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<LL> VL;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;

template <typename T>
void read(T &x) {
    int s = 0, c = getchar();
    x = 0;
    while (isspace(c)) c = getchar();
    if (c == 45) s = 1, c = getchar();
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
    int b[40], l = 0;
    if (x < 0) putchar(45), x = -x;
    while (x > 0) b[l++] = x % 10, x /= 10;
    if (!l) putchar(48);
    while (l) putchar(b[--l] | 48);
    putchar(c);
}

int main(void) {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    /* int kase; read(kase);
    for (int i = 1; i <= kase; i++) {
        printf("Case #%d: ", i);
    } */
    int n,m;
    cin>>n>>m;
    unordered_map<string,int> qwq;
    qwq.clear();
    string s[n+1];
    for(int i=0;i<n;++i){
        cin>>s[i];
        qwq[s[i]]=i+1;
    }
    int ans=0;
    for(int i=0;i<n-2;++i)
        for(int j=i+1;j<n-1;++j){
            string ss;
            for(int k=0;k<m;++k){
                if (s[i][k]==s[j][k]) ss=ss+s[i][k];
                else if (s[i][k]!='S'&&s[j][k]!='S') ss=ss+'S';
                else if (s[i][k]!='T'&&s[j][k]!='T') ss=ss+'T';
                else if (s[i][k]!='E'&&s[j][k]!='E') ss=ss+'E';
            }
            if (qwq[ss]>j) ++ans;
        }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define MIN(a,b) ((((a)<(b)?(a):(b))))
#define MAX(a,b) ((((a)>(b)?(a):(b))))
#define ABS(a) ((((a)>0?(a):-(a))))
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<PII> VPII;
typedef vector<LL> VL;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;

template <typename T>
void read(T &x) {
    int s = 0, c = getchar();
    x = 0;
    while (isspace(c)) c = getchar();
    if (c == 45) s = 1, c = getchar();
    while (isdigit(c)) x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
    if (s) x = -x;
}

template <typename T>
void write(T x, char c = ' ') {
    int b[40], l = 0;
    if (x < 0) putchar(45), x = -x;
    while (x > 0) b[l++] = x % 10, x /= 10;
    if (!l) putchar(48);
    while (l) putchar(b[--l] | 48);
    putchar(c);
}

int main(void) {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    /* int kase; read(kase);
    for (int i = 1; i <= kase; i++) {
        printf("Case #%d: ", i);
    } */
    int n,m;
    cin>>n>>m;
    unordered_map<string,int> qwq;
    qwq.clear();
    string s[n+1];
    for(int i=0;i<n;++i){
        cin>>s[i];
        qwq[s[i]]=i+1;
    }
    int ans=0;
    for(int i=0;i<n-2;++i)
        for(int j=i+1;j<n-1;++j){
            string ss;
            for(int k=0;k<m;++k){
                if (s[i][k]==s[j][k]) ss.push_back(s[i][k]);
                else if (s[i][k]!='S'&&s[j][k]!='S') ss.push_back('S');
                else if (s[i][k]!='T'&&s[j][k]!='T') ss.push_back('T');
                else if (s[i][k]!='E'&&s[j][k]!='E') ss.push_back('E');
            }
            cout<<ss<<endl;
            if (qwq[ss]>j) ++ans;
        }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(string str1,string str2)
{
	return str1<str2;
}
string str[1505];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>str[i];
	sort(str,str+n);
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			char cnt[k];
			for(int l=0;l<k;l++)
			{
				if(str[i][l]==str[j][l])
					cnt[l]=str[i][l];
				else
				{
					if(str[i][l]!='S'&&str[j][l]!='S')
						cnt[l]='S';
					else
					{
						if(str[i][l]!='E'&&str[j][l]!='E')
							cnt[l]='E';
						else
							cnt[l]='T';
					}
				}
			}
//			cout<<"cnt:"<<cnt<<endl;
			int l=0,r=n-1;
			while(l<r)
			{
				int mid=(l+r)>>1;
				if(str[mid]>cnt)
					r=mid-1;
				else
				{
					if(str[mid]<cnt)
						l=mid+1;
					else
						break;
				}
			}
			if((l+r)/2!=i&&(l+r)/2!=j&&cnt==str[(l+r)/2])
				ans++;
		}
	}
	cout<<ans/3;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(string str1,string str2)
{
	return str1<str2;
}
string str[1505];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>str[i];
	sort(str,str+n);
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			char cnt[35];
			for(int l=0;l<k;l++)
			{
				if(str[i][l]==str[j][l])
					cnt[l]=str[i][l];
				else
				{
					if(str[i][l]!='S'&&str[j][l]!='S')
						cnt[l]='S';
					else
					{
						if(str[i][l]!='E'&&str[j][l]!='E')
							cnt[l]='E';
						else
							cnt[l]='T';
					}
				}
			}
//			cout<<"cnt:"<<cnt<<endl;
			int l=0,r=n-1;
			while(l<=r)
			{
				int mid=(l+r)/2;
//				cout<<"l:"<<l<<" r:"<<r<<" mid:"<<mid<<endl;
				if(str[mid]>cnt)
					r=mid-1;
				else
				{
					if(str[mid]<cnt)
						l=mid+1;
					else
						break;
				}
			}
			if((l+r)/2!=i&&(l+r)/2!=j&&cnt==str[(l+r)/2])
				ans++;
		}
	}
	cout<<ans/3;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5;
const int SET='S'+'E'+'T';
string s[N];
map<string,int>mp;
int n,k,ans;
int main()
{
	scanf("%d %d",&n,&k);
	for(int i=0;i<n;i++) cin>>s[i],mp[s[i]]++;
	for(int i=0;i<n;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			string t="";
			for(int p=0;p<k;p++)
			{
				if(s[i][p]==s[j][p])  t+=s[i][p];
				else t+=SET-s[i][p]-s[j][p];
			}
			if(mp.count(t))  ans+=mp[t];
		}
	}
	cout<<ans/3<<endl;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(string str1,string str2)
{
	return str1<str2;
}
string str[1505];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>str[i];
	sort(str,str+n);
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			char cnt[k];
			for(int l=0;l<k;l++)
			{
				if(str[i][l]==str[j][l])
					cnt[l]=str[i][l];
				else
				{
					if(str[i][l]!='S'&&str[j][l]!='S')
						cnt[l]='S';
					else
					{
						if(str[i][l]!='E'&&str[j][l]!='E')
							cnt[l]='E';
						else
							cnt[l]='T';
					}
				}
			}
			cout<<"cnt:"<<cnt<<endl;
			int l=0,r=n-1;
			while(l<r)
			{
				int mid=(l+r)>>1;
				if(str[mid]>cnt)
					r=mid-1;
				else
				{
					if(str[mid]<cnt)
						l=mid+1;
					else
						break;
				}
			}
			if((l+r)/2!=i&&(l+r)/2!=j&&cnt==str[(l+r)/2])
				ans++;
		}
	}
	cout<<ans/3;
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(string str1,string str2)
{
	return str1<str2;
}
string str[1505];
int main()
{
	int n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>str[i];
	sort(str,str+n);
	int ans=0;
	for(int i=0;i<n-1;i++)
	{
		for(int j=i+1;j<n;j++)
		{
			char cnt[k];
			for(int l=0;l<k;l++)
			{
				if(str[i][l]==str[j][l])
					cnt[l]=str[i][l];
				else
				{
					if(str[i][l]!='S'&&str[j][l]!='S')
						cnt[l]='S';
					else
					{
						if(str[i][l]!='E'&&str[j][l]!='E')
							cnt[l]='E';
						else
							cnt[l]='T';
					}
				}
			}
//			cout<<"cnt:"<<cnt<<endl;
			int l=0,r=n-1;
			while(l<=r)
			{
				int mid=(l+r)/2;
				if(str[mid]>cnt)
					r=mid-1;
				else
				{
					if(str[mid]<cnt)
						l=mid+1;
					else
						break;
				}
			}
			if((l+r)/2!=i&&(l+r)/2!=j&&cnt==str[(l+r)/2])
				ans++;
		}
	}
	cout<<ans/3;
	return 0;
}


#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long ll;
ll n,m,a;
ll find(ll key,bool pvis[],ll p[])
{
    ll l=1;
    ll h=m;
    ll i=1;
    if(key<p[1])
    {
        return 0;
    }
    while(l<=h)
    {
        if(key>p[l]&&key<p[h])
        {
            l++;
            h--;
        }
        else if(key>p[l])
        l++;
        else if(key<p[h])
        h--;
        else
        break;
    }
    for(i=h;i>=1;i--)
    {
        if(pvis[i]==false)
        {
            pvis[i]=true;
            return i;
        }
    }
    return 0;

}
ll search(ll key,bool pvis[],ll p[])
{
    ll i;
    for(i=1;i<=m;i++)
    {
        if(pvis[i]==false)
        {
            if(key+a>=p[i])
            {
                a=a+key-p[i];
                pvis[i]=true;
                return i;
            }
        }
    }
    return 0;
}
int main()
{
    SPEED;
    cin>>n>>m>>a;
    ll i;
    ll k=a;
    ll b[n+1];
    ll p[m+1];
     bool bvis[n+1];
     bool pvis[m+1];
     ll sum=0;
    for(i=1;i<=n;i++)
    {
        cin>>b[i];
        bvis[i]=false;
    }
    for(i=1;i<=m;i++)
    {
        cin>>p[i];
        pvis[i]=false;
    }
   // cout<<1;
    ll x;
    sort(b+1,b+n+1);
    sort(p+1,p+m+1);
   // cout<<1;
    for(i=n;i>=1;i--)
    {
        x=find(b[i],pvis,p);
        if(x){
        bvis[i]=true;
       // sum+=p[x];
      // cout<<x<<" ";
        }
    }
    ll count=0;
   /** for(i=1;i<=n;i++)
    {
        if(bvis[i])
        count++;
    }
    cout<<count<<endl;**/
    for(i=n;i>=1;i--)
    {
        if(bvis[i]==false)
        {
            x=search(b[i],pvis,p);
            //cout<<x<<" ";
            if(x)
            bvis[i]=true;
        }
    }

    for(i=1;i<=m;i++)
    {
        if(pvis[i])
        count++;
    }

    for(i=1;i<=count;i++)
    {

        sum=sum+p[i];
    }
    cout<<count<<endl;
   // sum=sum;
    if(sum>=k)
    cout<<sum-k;
    else
    cout<<0;

}


#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long ll;
int n,m,p;
int a[100009];
int b[100009];

bool check(int pos)
{
    int i,j;
    j=pos;
    int count=pos;
    int A=p;
    for(i=n-1;i>=0&&j>=0;j--,i--)
    {
        if(a[i]+A<b[j])return false;
        if(a[i]+A>b[j])
        {
            A=A+a[i]-b[j];
            count--;
        }
    }
    return count<0;
}
int main()
{
    SPEED;
    cin>>n>>m>>p;
    int i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<m;i++)
    cin>>b[i];
    sort(a,a+n);
    sort(b,b+m);
    int low=-1;
    int high =m;
    int mid;
    int ans=-1;
    while(high-low>1)
    {
        mid=(high+low)/2;
        if(check(mid))
        {
            low=mid;
            ans=mid;
        }
        else
        high=mid;
    }
    if (low == -1)
    {
        cout <<0<<endl<<0;
        return 0;
    }
    ll sum=0;
    for(i=0;i<=ans;i++){
    sum+=b[i];
    //cout<<sum<<endl;
    }
    cout<<ans+1<<endl;
     cout<<max(sum-p,(ll)0);
}


#include <bits/stdc++.h>
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
typedef long long ll;
int n,m,p;
int a[100009];
int b[100009];

bool check(int pos)
{
    int i,j;
    j=pos;
    int count=pos;
    int A=p;
    for(i=n-1;i>=0&&j>=0;j--,i--)
    {
        if(a[i]+A<b[j])return false;
        if(a[i]+A>b[j])
        {
            A=A+a[i]-b[j];
            count--;
        }
    }
    return count<0;
}
int main()
{
    SPEED;
    cin>>n>>m>>p;
    int i;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n;i++)
    cin>>b[i];
    sort(a,a+n);
    sort(b,b+m);
    int low=-1;
    int high =m;
    int mid;
    int ans=-1;
    while(high-low>1)
    {
        mid=(high+low)/2;
        if(check(mid))
        {
            low=mid;
            ans=mid;
        }
        else
        high=mid;
    }
    if (low == -1)
    {
        cout <<0<<endl<<0;
        return 0;
    }
    ll sum=0;
    for(i=0;i<=ans;i++)
    sum+=b[i];
    cout<<ans+1<<endl;
     cout<<max(sum-p,(ll)0);
}


#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
ll n,m,a;
ll find(ll key,bool pvis[],ll p[])
{
    ll l=1;
    ll h=m;
    ll i=1;
    if(key<p[1])
    {
        return 0;
    }
    while(l<=h)
    {
        if(key>p[l]&&key<p[h])
        {
            l++;
            h--;
        }
        else if(key>p[l])
        l++;
        else if(key<p[h])
        h--;
        else
        break;
    }
    for(i=h;i>=1;i--)
    {
        if(pvis[i]==false)
        {
            pvis[i]=true;
            return i;
        }
    }
    return 0;

}
ll search(ll key,bool pvis[],ll p[])
{
    ll i;
    for(i=1;i<=m;i++)
    {
        if(pvis[i]==false)
        {
            if(key+a>=p[i])
            {
                a=a+key-p[i];
                pvis[i]=true;
                return i;
            }
        }
    }
    return 0;
}
int main()
{
    cin>>n>>m>>a;
    ll i;
    ll k=a;
    ll b[n+1];
    ll p[m+1];
     bool bvis[n+1];
     bool pvis[m+1];
     ll sum=0;
    for(i=1;i<=n;i++)
    {
        cin>>b[i];
        bvis[i]=false;
    }
    for(i=1;i<=m;i++)
    {
        cin>>p[i];
        pvis[i]=false;
    }
   // cout<<1;
    ll x;
    sort(b+1,b+n+1);
    sort(p+1,p+m+1);
   // cout<<1;
    for(i=n;i>=1;i--)
    {
        x=find(b[i],pvis,p);
        if(x){
        bvis[i]=true;
       // sum+=p[x];
      // cout<<x<<" ";
        }
    }
    ll count=0;
   /** for(i=1;i<=n;i++)
    {
        if(bvis[i])
        count++;
    }
    cout<<count<<endl;**/
    for(i=n;i>=1;i--)
    {
        if(bvis[i]==false)
        {
            x=search(b[i],pvis,p);
            //cout<<x<<" ";
            if(x)
            bvis[i]=true;
        }
    }

    for(i=1;i<=m;i++)
    {
        if(pvis[i])
        count++;
    }

    for(i=1;i<=count;i++)
    {

        sum=sum+p[i];
    }
    cout<<count<<endl;
   // sum=sum;
    if(sum>=k)
    cout<<sum-k;
    else
    cout<<0;

}


#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main(){
    int n, m, a;
    cin >> n >> m >> a;
    vector<int> b(n), p(m);
    for(int i = 0; i<n; i++){
        cin >> b[i];
    }
    for(int i = 0; i<m; i++){
        cin >> p[i];
    }

    sort(b.begin(), b.end());
    sort(p.begin(), p.end());

    int lo = 0, hi = min(m, n);
    while(lo < hi){
        int mid = (lo + hi + 1)/ 2;
        int bike_idx = mid - 1;
        int student_idx = n-1;
        int additional = 0;
        // cout << mid << "\n";
        for(int i = 0; i<mid; i++){
            // cout << p[bike_idx] << " " << b[student_idx] << "\n";
            additional += max((int)0, p[bike_idx]-b[student_idx]);
            bike_idx--;
            student_idx--;
        }
        // cout << additional << "\n";
        if(additional > a){
            hi = mid - 1;
        }
        else{
            lo = mid;
        }
    }

    int student_idx = n-1;
    int bike_idx = lo-1;
    int s  = 0;
    for(int i = 0; i<=bike_idx; i++){
        if(p[i] > a){
            s+=(p[i]-a);
            a = 0;
        }
        else{
            a = a-p[i];
        }
    }
    cout << lo << " " << s << "\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int32_t main(){
    speed;
    int n, m, a;
    cin >> n >> m >> a;
    vector<int> b(n), p(m);
    for(int i = 0; i<n; i++){
        cin >> b[i];
    }
    for(int i = 0; i<m; i++){
        cin >> p[i];
    }

    sort(b.begin(), b.end(), greater<int>());
    sort(p.begin(), p.end());

    int lo = 0, hi = n;
    while(lo < hi){
        int mid = (lo + hi + 1) >> 1;
        int extra = 0;
        int pos = 0;
        for(int i = mid-1; i>=0; i--){
            int pm = b[i];
            int bm = p[pos++];
            extra += max((int)0, bm - pm);

        }
        if(extra > a){
            hi = mid - 1;

        }
        else if(extra <= a){
            lo = mid;
        }
    }
    int r = lo;
    int s = 0;
    int pos = 0;
    for(int i = lo-1; i>=0; i--){
        int pm = b[i];
        int bm = p[pos++];
        s+=min(pm, bm);
        int extra = max((int)0, bm - pm);
        a-=extra;
    }
    s-=a;
    cout << r << " " << s <<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int32_t main(){
    speed;
    int n, m, a;
    cin >> n >> m >> a;
    vector<int> b(n), p(m);
    for(int i = 0; i<n; i++){
        cin >> b[i];
    }
    for(int i = 0; i<m; i++){
        cin >> p[i];
    }

    sort(b.begin(), b.end(), greater<int>());
    sort(p.begin(), p.end());

    int lo = 0, hi = min(n, m);
    while(lo < hi){
        int mid = (lo + hi + 1) >> 1;
        int extra = 0;
        int pos = 0;
        for(int i = mid-1; i>=0; i--){
            int pm = b[i];
            int bm = p[pos++];
            extra += max((int)0, bm - pm);

        }
        if(extra > a){
            hi = mid - 1;

        }
        else if(extra <= a){
            lo = mid;
        }
    }
    int r = lo;
    int s = 0;
    int pos = 0;
    for(int i = lo-1; i>=0; i--){
        int pm = b[i];
        int bm = p[pos++];
        s+=min(pm, bm);
        int extra = max((int)0, bm - pm);
        a-=extra;
    }
    s-=a;
    s = max((int)0, s);
    cout << r << " " << s <<"\n";
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int32_t main(){
    speed;
    int n, m, a;
    cin >> n >> m >> a;
    vector<int> b(n), p(m);
    for(int i = 0; i<n; i++){
        cin >> b[i];
    }
    for(int i = 0; i<m; i++){
        cin >> p[i];
    }

    sort(b.begin(), b.end(), greater<int>());
    sort(p.begin(), p.end());

    int lo = 0, hi = min(n, m);
    while(lo < hi){
        int mid = (lo + hi + 1) >> 1;
        int extra = 0;
        int pos = 0;
        for(int i = mid-1; i>=0; i--){
            int pm = b[i];
            int bm = p[pos++];
            extra += max((int)0, bm - pm);

        }
        if(extra > a){
            hi = mid - 1;

        }
        else if(extra <= a){
            lo = mid;
        }
    }
    int r = lo;
    int s = 0;
    int pos = 0;
    for(int i = lo-1; i>=0; i--){
        int pm = b[i];
        int bm = p[pos++];
        s+=min(pm, bm);
        int extra = max((int)0, bm - pm);
        a-=extra;
    }
    s-=a;
    cout << r << " " << s <<"\n";
    return 0;
}


// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define in(x) 		scanf("%d", &x)
#define echo(x)		printf("%d", x)
#define inf 		(int)(1e18)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

// Code from Here -------------------------------------------------------------------------------

bool check(int mid, vi a, vi b, int n, int m, int k){
	int c=mid-1;
	for(int i=0; i<mid; i++){
		if(a[i]+k >= b[c]){
			k-=max(0ll, -a[i]+b[c]);
			c--;
		}
		else{
			return false;
		}
	}
	return true;
}

int calc(vi a, vi b, int n, int m, int ans, int k){
	int c=ans-1;
	int sum=0;
	for(int i=0; i<ans; i++){
		if(b[c]<=a[i]){
			sum+=b[c];
		}
		else{
			sum+=a[i];
			k-=(b[c]-a[i]);
		}
		c--;
	}
	sum-=k;
	return sum;
}

signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n,m,k;
	cin >> n >> m >> k;
	vi a(n), b(m);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<m; i++){
		cin >> b[i];
	}
	sort(rall(a));
	sort(all(b));
	// debug(a);
	// debug(b);
	int l=0, r=min(n,m), ans=0;
	while(l<=r){
		int mid=l+(r-l)/2;
		if(check(mid, a, b, n, m, k)){
			l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	ans=l-1;
	cout << ans << " ";
	cout << calc(a,b,n,m,ans,k);

	return 0;
}


// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define in(x) 		scanf("%d", &x)
#define echo(x)		printf("%d", x)
#define inf 		(int)(1e18)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

// Code from Here -------------------------------------------------------------------------------

bool check(int mid, vi a, vi b, int n, int m, int k){
	int c=mid-1;
	for(int i=0; i<mid; i++){
		if(a[i]+k >= b[c]){
			c--;
			k-=max(0ll, -a[i]+b[c]);
		}
		else{
			return false;
		}
	}
	return true;
}

int calc(vi a, vi b, int n, int m, int ans, int k){
	int c=ans-1;
	int sum=0;
	for(int i=0; i<ans; i++){
		if(b[c]<=a[i]){
			sum+=b[c];
		}
		else{
			sum+=a[i];
			k-=(b[c]-a[i]);
		}
		c--;
	}
	sum-=k;
	return sum;
}

signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n,m,k;
	cin >> n >> m >> k;
	vi a(n), b(m);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<m; i++){
		cin >> b[i];
	}
	sort(rall(a));
	sort(all(b));
	// debug(a);
	// debug(b);
	int l=0, r=min(n,m), ans=0;
	while(l<=r){
		int mid=l+(r-l)/2;
		if(check(mid, a, b, n, m, k)){
			l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	ans=l-1;
	cout << ans << " ";
	cout << calc(a,b,n,m,ans,k);

	return 0;
}


// Best practice

#include<bits/stdc++.h>

#define int         long long
#define pb          push_back
#define pf          emplace_front
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define pii 		pair<int,int>
#define psi 		pair<string,int>
#define vi 			vector<int>
#define vpii  		vector<pii>
#define vvi 		vector<vi>
#define sz(x)	    (int)(x).size()
#define x           first
#define y           second
#define endl        '\n'
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MOD         1000000007
#define hell        998244353
#define prec(n) 	fixed<<setprecision(n)
#define in(x) 		scanf("%d", &x)
#define echo(x)		printf("%d", x)
#define inf 		(int)(1e18)
#define ini(a, i) 	memset(a, i, sizeof(a))
#define output(x)   cout << (x ? "YES" : "NO")<<endl;
using namespace std;

#define debug(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<i<<" "; cout<< "]" << endl
#define debugp(vec) cout<<(#vec)<<" : [ "; for (auto& i: vec) cout<<"("<<i.x<<","<<i.y<<")"<<" "; cout<< "]" << endl
#define trace(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args);cout << endl; }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << "[" << *it << ": " << a << "]\t";
    err(++it, args...);
}

// const int dx[4] = { -1, 1, 0, 0};
// const int dy[4] = {0, 0, -1, 1};
// int dX[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
// int dY[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

// Code from Here -------------------------------------------------------------------------------

bool check(int mid, vi a, vi b, int n, int m, int k){
	int c=mid-1;
	for(int i=0; i<mid; i++){
		if(a[i]+k >= b[c]){
			k-=max(0ll, -a[i]+b[c]);
			c--;
		}
		else{
			return false;
		}
	}
	return true;
}

int calc(vi a, vi b, int n, int m, int ans, int k){
	int c=ans-1;
	int sum=0;
	for(int i=0; i<ans; i++){
		if(b[c]<=a[i]){
			sum+=b[c];
		}
		else{
			sum+=a[i];
			k-=(b[c]-a[i]);
		}
		c--;
	}
	sum-=k;
	sum=max(sum,0ll);
	return sum;
}

signed main() {
	tezz

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n,m,k;
	cin >> n >> m >> k;
	vi a(n), b(m);
	for(int i=0; i<n; i++){
		cin >> a[i];
	}
	for(int i=0; i<m; i++){
		cin >> b[i];
	}
	sort(rall(a));
	sort(all(b));
	// debug(a);
	// debug(b);
	int l=0, r=min(n,m), ans=0;
	while(l<=r){
		int mid=l+(r-l)/2;
		if(check(mid, a, b, n, m, k)){
			l=mid+1;
		}
		else{
			r=mid-1;
		}
	}
	ans=l-1;
	cout << ans << " ";
	cout << calc(a,b,n,m,ans,k);

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int MAXN = 1000 * 100 * 2 + 10;
ll ans[MAXN];
ll p[MAXN];
ll b[MAXN];
bool mark[MAXN];
bool markb[MAXN];

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n, m, a, a2, ans1 = 0;
	cin >> n >> m >> a;
	a2 = a;
	for(int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	for(int i = 0; i < m; i++)
	{
		cin >> p[i];
	}
	sort(b, b+n);
	sort(p, p+m);
	for(int i = 0; i < n; i++)
	{
		int s = 0, e = m, c = -1;
		while(s < e)
		{
			int mid = (s + e)/2;
			if(mark[mid])
			{
				s++;
			}
			else
			{
				if(p[mid] > b[i])
				{
					e = mid;
				}
				else
				{
					c = mid;
					s = mid + 1;
				}
			}
		}
		if(c != -1)
		{
			ans1++;
			//cout << b[i] << endl;
			//cout << p[c] << endl;
			ans[i] = c;
			mark[c] = true;
			markb[i] = true;
		}
	}
	int ptr = 0;
	while(ptr < m && mark[ptr])
	{
		ptr++;
	}
	for(int i = 0; i < n; i++)
	{
		if(!markb[i] && b[i] + a >= p[ptr])
		{
			a -= (p[ptr] - b[i]);
			mark[ptr] = true;
			//markb[i] = true;
			ans1++;
			//cout << p[ptr] << endl;
			ptr++;
			while(ptr < m-1 && mark[ptr])
			{
				ptr++;
			}
		}
	}
	int ans2 = 0;
	for(int i = 0; i < ans1; i++)
	{
		ans2 += p[i];
	}
	cout << ans1 << ' ' << max(ans2 - a2, 0) << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int MAXN = 1000 * 100 + 10;
ll p[MAXN];
ll b[MAXN];
bool mark[MAXN];
bool markb[MAXN];

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n, m, a;
	cin >> n >> m >> a;
	for(int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	for(int i = 0; i < m; i++)
	{
		cin >> p[i];
	}
	sort(b, b+n);
	sort(p, p+m);
	reverse(b, b+n);
	int s = 0, e = min(n, m) + 1, ans = 0;
	while(s < e)
	{
		int mid = (s + e)/2;
		reverse(b, b+mid);
		int su = 0;
		for(int i = 0; i < mid; i++)
		{
			if(p[i] > b[i])
			{
				su += p[i]-b[i];
			}
		}
		reverse(b, b+mid);
	//	cout << mid << ' ' << su << endl;
		if(su <= a)
		{
			ans = mid;
			s = mid+1;
		}
		else
		{
			e = mid;
		}
	}

	int ans2 = 0;
	for(int i = 0; i < ans; i++)
	{
		ans2 += p[i];
	}

	cout << ans << ' ' << max(0, ans2-a) << endl;

	return 0;
}


#include<bits/stdc++.h>

using namespace std;

typedef long long int ll;

const int MAXN = 1000 * 100 + 10;
ll ans[MAXN];
ll p[MAXN];
ll b[MAXN];
bool mark[MAXN];
bool markb[MAXN];

int main()
{
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	int n, m, a, a2, ans1 = 0;
	cin >> n >> m >> a;
	a2 = a;
	for(int i = 0; i < n; i++)
	{
		cin >> b[i];
	}
	for(int i = 0; i < m; i++)
	{
		cin >> p[i];
	}
	sort(b, b+n);
	sort(p, p+m);
	for(int i = 0; i < n; i++)
	{
		int s = 0, e = m, c = -1;
		while(s < e)
		{
			int mid = (s + e)/2;
			if(mark[mid])
			{
				s++;
			}
			else
			{
				if(p[mid] > b[i])
				{
					e = mid;
				}
				else
				{
					c = mid;
					s = mid + 1;
				}
			}
		}
		if(c != -1)
		{
			ans1++;
			//cout << b[i] << endl;
			ans[i] = c;
			mark[c] = true;
			markb[i] = true;
		}
	}
//	cout << ans1 << endl;
	int ptr = 0;
	while(ptr < m && mark[ptr])
	{
		ptr++;
	}
	reverse(b, b+n);
	reverse(markb, markb + n);
	for(int i = 0; i < n; i++)
	{
		if(!markb[i] && b[i] + a >= p[ptr] && !mark[ptr] && ptr < m)
		{
			a -= (p[ptr] - b[i]);
			mark[ptr] = true;
			//markb[i] = true;
			ans1++;
		//	cout << ptr << endl;
			ptr++;
			while(ptr < m && mark[ptr])
			{
				ptr++;
			}
		}
	}
	int ans2 = 0;
	for(int i = 0; i < ans1; i++)
	{
		ans2 += p[i];
	}
	cout << ans1 << ' ' << max(ans2 - a2, 0) << endl;

	return 0;
}