#include<iostream>
#include<cstdio>
#include<sstream>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<deque>
#include<queue>
#include<stack>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<bitset>
#include<cctype>
using namespace std;

typedef long long ll;
#define INF 2023456789
#define EPS 1e-11
#define PI acos(-1)
#define FOR(i,a,b) for(int i = a; i < b; ++i)
#define REP(i,a,b) for(int i = a; i <= b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define FORV(i,vt) for(size_t i = 0; i < vt.size(); ++i)

int gcd(int x, int y) {
    return y == 0 ? x : gcd(y, x % y);
}

int toInt(char xx) {
    return xx - '0';
}

char toChar(int xx) {
    return xx + '0';
}

bool isNum(char xx) {
    return ('0' <= xx && xx <= '9');
}

string s, p;
int res = 0;

void read() {
    cin >> s >> p;
}

bool anagram(string x, string y){ // x : consider, y : base
    map<char, int> mp1, mp2;
    int nz = 0;
    int len = x.length();
    FOR(i,0,len){
        if(x[i] != '?')
            mp1[x[i]]++;
        else {
            nz++;
        }
        mp2[y[i]]++;
    }
    int differ = 0;
    FOR(i,0,len){
        if(mp1[x[i]] > mp2[x[i]]){
            return false;
        }
        differ += mp2[x[i]] - mp1[x[i]];
    }
    if(differ == 0 || differ == nz){
        return true;
    }
    return false;
}

void init() {

}

void solve() {
    string tmp = "";
    int lens = s.length();
    int lenp = p.length();
    REP(i,0,lens-lenp){
        tmp = s.substr(i,lenp);
        if(anagram(tmp, p)){
            //cout << "tmp = " << tmp << " p = " << p << endl;
            res++;
        }
    }
    cout << res;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
#endif
    read();
    init();
    solve();
}


// Codeforces.com - Problem 144C
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

// DEFINE
#define FOR(i,a,b)     for (int i=(a),_b=(b); i<_b; i++)
#define RFOR(i,b,a)    for (int i=(b)-1,_a=(a); i>=_a; i--)
#define RESET(a,b)      memset((a),(b),sizeof(a))
#define fi              first
#define se              second
#define foreach(i, c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

//
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <string> vs;
typedef long long int64; //NOTES:int64
typedef unsigned long long uint64; //NOTES:uint64
typedef unsigned uint;
const double pi = acos(-1.0); //NOTES:pi
const double eps = 1e-11; //NOTES:eps
const int MAXI = 0x7fffffff;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}
// CODE
int ip[26], is[26];
int main(int argc, char *argv[])
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    string s, p;
    cin >> s >> p;
    FOR(i,0,p.size())
    {
        ip[p[i]-'a']++;
        if(s[i] == '?')
            is[25]++;
        else
            is[s[i]-'a']++;
    }
    bool f;
    f = true;
    int tmp, cnt;
    cnt = 0;
    tmp = is[25];
    FOR(i,0,25)
    {
        if(is[i] > ip[i] || tmp < 0)
        {
            f = false;
            break;
        }
        if(is[i] < ip[i])
            tmp -= ip[i]-is[i];
    }
    if(f)
        cnt++;
    //
    FOR(i,p.size(), s.size())
    {
        if(s[i-p.size()] == '?')
            is[25]--;
        else
            is[s[i-p.size()]-'a']--;
        if(s[i] == '?')
            is[25]++;
        else
            is[s[i]-'a']++;
       // FOR(j,0,26)
         //   cout << is[j] << " ";
        //cout << endl;
        tmp = is[25];
        f = true;
        FOR(j,0,25)
        {
            if(is[j] > ip[j] || tmp < 0)
            {
                f = false;
                break;
            }
            if(is[j] < ip[j])
                tmp -= ip[j] - is[j];
        }
        if(f)
            cnt++;
    }
    cout << cnt;
    return 0;
}


// Codeforces.com - Problem 144C
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

// DEFINE
#define FOR(i,a,b)     for (int i=(a),_b=(b); i<_b; i++)
#define RFOR(i,b,a)    for (int i=(b)-1,_a=(a); i>=_a; i--)
#define RESET(a,b)      memset((a),(b),sizeof(a))
#define fi              first
#define se              second
#define foreach(i, c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

//
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <string> vs;
typedef long long int64; //NOTES:int64
typedef unsigned long long uint64; //NOTES:uint64
typedef unsigned uint;
const double pi = acos(-1.0); //NOTES:pi
const double eps = 1e-11; //NOTES:eps
const int MAXI = 0x7fffffff;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}
// CODE
int ip[26], is[26];
int main(int argc, char *argv[])
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    string s, p;
    cin >> s >> p;
    if(s.size() < p.size())
    {
        cout << 0;
        return 0;
    }
    FOR(i,0,p.size())
    {
        ip[p[i]-'a']++;
        if(s[i] == '?')
            is[25]++;
        else
            is[s[i]-'a']++;
    }
    bool f;
    f = true;
    int tmp, cnt;
    cnt = 0;
    tmp = is[25];
    FOR(i,0,25)
    {
        if(is[i] > ip[i] || tmp < 0)
        {
            f = false;
            break;
        }
        if(is[i] < ip[i])
            tmp -= ip[i]-is[i];
    }
    if(f)
        cnt++;
    //
    FOR(i,p.size(), s.size())
    {
        if(s[i-p.size()] == '?')
            is[25]--;
        else
            is[s[i-p.size()]-'a']--;
        if(s[i] == '?')
            is[25]++;
        else
            is[s[i]-'a']++;
       // FOR(j,0,26)
         //   cout << is[j] << " ";
        //cout << endl;
        tmp = is[25];
        f = true;
        FOR(j,0,25)
        {
            if(is[j] > ip[j] || tmp < 0)
            {
                f = false;
                break;
            }
            if(is[j] < ip[j])
                tmp -= ip[j] - is[j];
        }
        if(f)
            cnt++;
    }
    cout << cnt;
    return 0;
}


// Codeforces.com - Problem 144C
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

// DEFINE
#define FOR(i,a,b)     for (int i=(a),_b=(b); i<_b; i++)
#define RFOR(i,b,a)    for (int i=(b)-1,_a=(a); i>=_a; i--)
#define RESET(a,b)      memset((a),(b),sizeof(a))
#define fi              first
#define se              second
#define foreach(i, c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

//
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <string> vs;
typedef long long int64; //NOTES:int64
typedef unsigned long long uint64; //NOTES:uint64
typedef unsigned uint;
const double pi = acos(-1.0); //NOTES:pi
const double eps = 1e-11; //NOTES:eps
const int MAXI = 0x7fffffff;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}
// CODE
int ip[27], is[27];
int main(int argc, char *argv[])
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    string s, p;
    cin >> s >> p;
    if(s.size() < p.size())
    {
        cout << 0;
        return 0;
    }
    FOR(i,0,p.size())
    {
        ip[p[i]-'a']++;
        if(s[i] == '?')
            is[26]++;
        else
            is[s[i]-'a']++;
    }
    bool f;
    f = true;
    int tmp, cnt;
    cnt = 0;
    tmp = is[26];
    FOR(i,0,26)
    {
        if(is[i] > ip[i] || tmp < 0)
        {
            f = false;
            break;
        }
        if(is[i] < ip[i])
            tmp -= ip[i]-is[i];
    }
    if(f)
        cnt++;
    //
    FOR(i,p.size(), s.size())
    {
        if(s[i-p.size()] == '?')
            is[26]--;
        else
            is[s[i-p.size()]-'a']--;
        if(s[i] == '?')
            is[26]++;
        else
            is[s[i]-'a']++;
       // FOR(j,0,26)
         //   cout << is[j] << " ";
        //cout << endl;
        tmp = is[26];
        f = true;
        FOR(j,0,26)
        {
            if(is[j] < ip[j] && (tmp - ip[j] - is[j]) >= 0)
                tmp -= ip[j] - is[j];
            if(is[j] > ip[j] || tmp < 0)
            {
                f = false;
                break;
            }
        }
        if(f)
            cnt++;
    }
    cout << cnt;
    return 0;
}


// Codeforces.com - Problem 144C
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#define FOR(i,begin,end) for(int i = (int)begin; i < (int)end; i++)
#define foreach(i,c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

using namespace std;
map <char,int> chb;
bool check(string s)
{
    map <char,int> chs;
    int q;
    q = 0;
    FOR(i,0,s.size())
    {
        if(s[i] != '?')
            chs[s[i]]++;
        else
            q++;
    }
    if(q == s.size())
        return true;
    bool f;
    f = false;
    FOR(i,0,s.size())
    {
        if(s[i] != '?' && chb[s[i]] != 0 && chs[s[i]] + q == chb[s[i]])
        {
            f = true;
        //  cout << chs[s[i]] << " " << chb[s[i]] << endl;
        }
    }
    return f;
}
int main(int argc, char *argv[])
{
    string a, b;
    cin >> a >> b;
    if(b.size() > a.size())
    {
        cout << 0;
        return 0;
    }
    FOR(i,0,b.size())
        chb[b[i]]++;

    int c;
    c = 0;
    //cout << check("b?a");
    FOR(i,0,a.size()- b.size() + 1)
    {
        string t;
        t = a.substr(i,b.size());
        if(check(t))
            c++;
        //cout << t << " " << check(t) << ": " << endl;
    }
    cout << c;
    return 0;
}


// Codeforces.com - Problem 144C
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#define FOR(i,begin,end) for(int i = (int)begin; i < (int)end; i++)
#define foreach(i,c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

using namespace std;
map <char,int> chb;
bool check(string s)
{
    map <char,int> chs;
    map <char,int>::iterator j;
    int q;
    q = 0;
    FOR(i,0,s.size())
    {
        if(s[i] != '?')
            chs[s[i]]++;
        else
            q++;
    }
    if(q == s.size())
        return true;
    FOR(i,0,s.size())
    {
        if((chs[s[i]] > chb[s[i]] || chb[s[i]] == 0) && s[i] != '?')
            return false;
    }
    return true;
}
int main(int argc, char *argv[])
{
    string a, b;
    cin >> a >> b;
    if(b.size() > a.size())
    {
        cout << 0;
        return 0;
    }
    FOR(i,0,b.size())
        chb[b[i]]++;

    int c;
    c = 0;
    //cout << check("b?a");
    FOR(i,0,a.size()- b.size() + 1)
    {
        string t;
        t = a.substr(i,b.size());
        if(check(t))
            c++;
    //  cout << t << " " << check(t) << ": " << endl;
    }
    cout << c;
    return 0;
}


// Codeforces.com - Problem 144C
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#define FOR(i,begin,end) for(int i = (int)begin; i < (int)end; i++)
#define foreach(i,c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

using namespace std;
map <char,int> chb;
bool check(string s)
{
    map <char,int> chs;
    int q;
    q = 0;
    FOR(i,0,s.size())
    {
        if(s[i] != '?')
            chs[s[i]]++;
        else
            q++;
    }
    if(q == s.size())
        return true;
    bool f;
    f = false;
    FOR(i,0,s.size())
    {
        if(s[i] != '?' && chs[s[i]] <= chb[s[i]])
            f = true;
    }
    return f;
}
int main(int argc, char *argv[])
{
    string a, b;
    cin >> a >> b;
    if(b.size() > a.size())
    {
        cout << 0;
        return 0;
    }
    FOR(i,0,b.size())
        chb[b[i]]++;

    int c;
    c = 0;
    FOR(i,0,a.size()- b.size() + 1)
    {
        string t;
        t = a.substr(i,b.size());
        if(check(t))
            c++;
    }
    cout << c;
    return 0;
}


// Codeforces.com - Problem 144C
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#define FOR(i,begin,end) for(long i = (long)begin; i < (long)end; i++)
#define foreach(i,c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

using namespace std;
map <char,long> chb;
bool check(string s)
{
    map <char,long> chs;
    long q;
    q = 0;
    FOR(i,0,s.size())
    {
        if(s[i] != '?')
            chs[s[i]]++;
        else
            q++;
    }
    if(q == s.size())
        return true;
    FOR(i,0,s.size())
    {
        if((chs[s[i]] > chb[s[i]] || chb[s[i]] == 0) && s[i] != '?')
            return false;
    }
    return true;
}
int main(int argc, char *argv[])
{
    string a, b;
    cin >> a >> b;
    if(b.size() > a.size())
    {
        cout << 0;
        return 0;
    }
    FOR(i,0,b.size())
        chb[b[i]]++;

    long c;
    c = 0;
    //cout << check("b?a");
    FOR(i,0,a.size()- b.size() + 1)
    {
        string t;
        t = a.substr(i,b.size());
        if(check(t))
            c++;
    //  cout << t << " " << check(t) << ": " << endl;
    }
    cout << c;
    return 0;
}


// Codeforces.com - Problem 144C
#include <set>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <cassert>
#include <vector>
#include <list>
#include <map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>

// DEFINE
#define FOR(i,a,b)     for (int i=(a),_b=(b); i<_b; i++)
#define RFOR(i,b,a)    for (int i=(b)-1,_a=(a); i>=_a; i--)
#define RESET(a,b)      memset((a),(b),sizeof(a))
#define fi              first
#define se              second
#define foreach(i, c)   for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++)

//
using namespace std;
typedef vector <int> vi;
typedef vector <vi> vvi;
typedef pair <int, int> ii;
typedef vector <ii> vii;
typedef vector <string> vs;
typedef long long int64; //NOTES:int64
typedef unsigned long long uint64; //NOTES:uint64
typedef unsigned uint;
const double pi = acos(-1.0); //NOTES:pi
const double eps = 1e-11; //NOTES:eps
const int MAXI = 0x7fffffff;
int in() {
    int x = 0, c;
    for (; (uint)((c = getchar()) - '0') >= 10; ) { if (c == '-') return -in(); if (!~c) throw ~0; }
    do { x = (x << 3) + (x << 1) + (c - '0'); } while ((uint)((c = getchar()) - '0') < 10);
    return x;
}
// CODE
int ip[26], is[26];
int main(int argc, char *argv[])
{
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    string s, p;
    cin >> s >> p;
    if(s.size() < p.size())
    {
        cout << 0;
        return 0;
    }
    FOR(i,0,p.size())
    {
        ip[p[i]-'a']++;
        if(s[i] == '?')
            is[25]++;
        else
            is[s[i]-'a']++;
    }
    bool f;
    f = true;
    int tmp, cnt;
    cnt = 0;
    tmp = is[25];
    FOR(i,0,25)
    {
        if(is[i] > ip[i] || tmp < 0)
        {
            f = false;
            break;
        }
        if(is[i] < ip[i])
            tmp -= ip[i]-is[i];
    }
    if(f)
        cnt++;
    //
    FOR(i,p.size(), s.size())
    {
        if(s[i-p.size()] == '?')
            is[25]--;
        else
            is[s[i-p.size()]-'a']--;
        if(s[i] == '?')
            is[25]++;
        else
            is[s[i]-'a']++;
       // FOR(j,0,26)
         //   cout << is[j] << " ";
        //cout << endl;
        tmp = is[25];
        f = true;
        FOR(j,0,25)
        {
            if(is[j] < ip[j] && (tmp - ip[j] - is[j]) >= 0)
                tmp -= ip[j] - is[j];
            if(is[j] > ip[j] || tmp < 0)
            {
                f = false;
                break;
            }
        }
        if(f)
            cnt++;
    }
    cout << cnt;
    return 0;
}


#include<iostream>
 #include<cmath>
 #include<vector>
 #include<algorithm>
 #include<string>
 #include<memory.h>
 #include<utility>
 #include<set>
 #include<map>
 #include<sstream>
 #include<cstdio>
 #include<cstdlib>
 #include<deque>
 #include<list>
 #include<numeric>
 using namespace std;
 string s,p;
 int n,i,j,a[30],res;
 bool isper(string s){
     int t[30];
     memset(t,0,sizeof(t));
     int r=0,q=0;
     for(int i=0;i<s.length();i++)
         if(s[i]=='?')r++; else t[s[i]-'a']++;
     if(r>=p.length()) return 1;
     for(int i=0;i<26;i++)
         if(t[i] && a[i]){
             q+=min(t[i],a[i]);
             if(r+q>=p.length()) return 1;
         }
     return 0;
 }
 int main(){
     cin>>s>>p;
     if(p.length()>s.length()){cout<<0<<endl; return 0;}
     int T=0;
     for(i=0;i<s.length();i++)
         if(s[i]=='?') T++;
     if(T==s.length()){cout<<T-p.length()+1<<endl; return 0;}
     for(i=0;i<p.length();i++)
         a[p[i]-'a']++;
     int x=s.length()-p.length();
     for(i=0;i<=x;i++)
         res+=isper(s.substr(i,p.length()));
     cout<<res<<endl;
 }


#include<iostream>
 #include<cmath>
 #include<vector>
 #include<algorithm>
 #include<string>
 #include<memory.h>
 #include<utility>
 #include<set>
 #include<map>
 #include<sstream>
 #include<cstdio>
 #include<cstdlib>
 #include<deque>
 #include<list>
 #include<numeric>
 using namespace std;
 string s,p;
 int n,i,j,a['z'+1],res;
 vector<string> mas;
 bool isper(string s){
     int t['z'+1];
     memset(t,0,sizeof(t));
     int r=0,q=0;
     for(int i=0;i<s.length();i++)
         if(s[i]=='?')r++; else t[s[i]]++;
     if(r>=p.length()) return 1;
     for(int i='a';i<='z';i++)
         if(t[i] && a[i]) q+=min(t[i],a[i]);
     if(r+q>=p.length()) return 1;
     return 0;
 }
 int main(){
     cin>>s>>p;
     if(p.length()>s.length()){cout<<0<<endl; return 0;}
     int T=0;
     for(i=0;i<s.length();i++)
         if(s[i]=='?') T++;
     if(T==s.length()){cout<<T-p.length()+1<<endl; return 0;}
     for(i=0;i<p.length();i++)
         a[p[i]]++;
     int x=s.length()-p.length();
     for(i=0;i<=x;i++)
         res+=isper(s.substr(i,p.length()));
     cout<<res<<endl;
 }


#include<iostream>
 #include<cmath>
 #include<vector>
 #include<algorithm>
 #include<string>
 #include<memory.h>
 #include<utility>
 #include<set>
 #include<map>
 #include<sstream>
 #include<cstdio>
 #include<cstdlib>
 #include<deque>
 #include<list>
 #include<numeric>
 using namespace std;
 string s,p;
 int n,i,j,a['z'+1],res;
 vector<string> mas;
 bool isper(string s){
     int t['z'+1];
     memset(t,0,sizeof(t));
     int r=0,q=0;
     for(int i=0;i<s.length();i++)
         if(s[i]=='?')r++; else t[s[i]]++;
     if(r>=p.length()) return 1;
     for(int i='a';i<='z';i++)
         if(t[i] && a[i]) q+=min(t[i],a[i]);
     if(r+q>=p.length()) return 1;
     return 0;
 }
 int main(){
     cin>>s>>p;
     if(p.length()>s.length()){cout<<0<<endl; return 0;}
     for(i=0;i<p.length();i++)
         a[p[i]]++;
     int x=s.length()-p.length();
     for(i=0;i<=x;i++)
         res+=isper(s.substr(i,p.length()));
     cout<<res<<endl;
 }


 #include<iostream>
 #include<cmath>
 #include<vector>
 #include<algorithm>
 #include<string>
 #include<memory.h>
 #include<utility>
 #include<set>
 #include<map>
 #include<sstream>
 #include<cstdio>
 #include<cstdlib>
 #include<deque>
 #include<list>
 #include<numeric>
 using namespace std;
 string s,p;
 int n,i,j,a['z'+1],res;
 vector<string> mas;
 bool isper(string s){
     int t['z'+1];
     memset(t,0,sizeof(t));
     int r=0,q=0;
     for(int i=0;i<s.length();i++)
         if(s[i]=='?')r++; else t[s[i]]++;
     if(r>=p.length()) return 1;
     for(int i='a';i<='z';i++)
         if(t[i] && a[i]) q+=min(t[i],a[i]);
     if(r+q>=p.length()) return 1;
     return 0;
 }
 int main(){
     cin>>s>>p;
     for(i=0;i<p.length();i++)
         a[p[i]]++;
     for(i=0;i<s.length();i++)
         mas.push_back(s.substr(i,p.size()));
     for(i=0;i<mas.size();i++)
         if(mas[i].length()==p.length())
         res+=isper(mas[i]);
     cout<<res<<endl;
 }


#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<memory.h>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<deque>
#include<list>
#include<numeric>
using namespace std;
string s,p;
int s1[30],p1[30],i,w,res;
bool ispr(int s1[],int p1[],int w){
    int d=0;
    for(int i=0;i<26;i++){
        if(s1[i]>p1[i]) return 0;
        d+=p1[i]-s1[i];
    }
    return d==w;
}
int main(){
    cin>>s>>p;
    for(i=0;i<p.length();i++){
        if(s[i]=='?') w++; else s1[s[i]-'a']++;
        p1[p[i]-'a']++;
    }
    for(int i=0;i<=s.length()-p.length();i++){
        if(ispr(s1,p1,w)) res++;
        if(s[i]=='?') w--;
        else s1[s[i]-'a']--;
        if(s[i+p.length()]=='?') w++;
        else s1[s[i+p.length()]-'a']++;
    }
    cout<<res<<endl;
}


#include<iostream>
 #include<cmath>
 #include<vector>
 #include<algorithm>
 #include<string>
 #include<memory.h>
 #include<utility>
 #include<set>
 #include<map>
 #include<sstream>
 #include<cstdio>
 #include<cstdlib>
 #include<deque>
 #include<list>
 #include<numeric>
 using namespace std;
 string s,p;
 int n,i,j,a['z'+1],res;
 vector<string> mas;
 bool isper(string s){
     int t['z'+1];
     memset(t,0,sizeof(t));
     int r=0,q=0;
     for(int i=0;i<s.length();i++)
         if(s[i]=='?')r++; else t[s[i]]++;
     if(r>=p.length()) return 1;
     for(int i='a';i<='z';i++)
         if(t[i] && a[i]) q+=min(t[i],a[i]);
     if(r+q>=p.length()) return 1;
     return 0;
 }
 int main(){
     cin>>s>>p;
     if(p.length()>s.length()){cout<<0<<endl; return 0;}
     for(i=0;i<p.length();i++)
         a[p[i]]++;
     int x=s.length()-p.length();
     for(i=0;i<=x;i++)
         mas.push_back(s.substr(i,p.length()));
     for(i=0;i<mas.size();i++)
         res+=isper(mas[i]);
     cout<<res<<endl;
 }


#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<memory.h>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<deque>
#include<list>
#include<numeric>
using namespace std;
string s,p;
int s1[30],p1[30],i,w,res;
bool ispr(int s1[],int p1[],int w){
    int d=0;
    for(int i=0;i<26;i++){
        if(s1[i]>p1[i]) return 0;
        d+=p1[i]-s1[i];
    }
    return d==w;
}
int main(){
int plen,slen;
    cin>>s>>p;
    slen=s.size();
    plen=p.size();

    for(i=0;i<p.size();i++){
        if(s[i]=='?') w++; else s1[s[i]-'a']++;
        p1[p[i]-'a']++;
    }
    for(int i=0;i<=slen-plen;i++){
        if(ispr(s1,p1,w)) res++;
        if(s[i]=='?') w--;
        else s1[s[i]-'a']--;
        if(i+plen<slen) if(s[i+plen]=='?') w++;
        else s1[s[i+plen]-'a']++;
    }
    cout<<res<<endl;
}


#include<string>
#include<iostream>
#include<vector>
 using namespace std;
 string s,p;
 int n,i,j,a['z'+1],res;
 vector<string> mas;
 bool isper(string s){
     int t['z'+1];
     memset(t,0,sizeof(t));
     int r=0,q=0;
     for(int i=0;i<s.length();i++)
         if(s[i]=='?')r++; else t[s[i]]++;
     if(r>=p.length()) return 1;
     for(int i='a';i<='z';i++)
         if(t[i] && a[i]) q+=min(t[i],a[i]);
     if(r+q>=p.length()) return 1;
     return 0;
 }
 int main(){
     cin>>s>>p;
     for(i=0;i<p.length();i++)
         a[p[i]]++;
     for(i=0;i<s.length();i++)
         mas.push_back(s.substr(i,p.size()));
     for(i=0;i<mas.size();i++)
         if(mas[i].length()==p.length())
         res+=isper(mas[i]);
     cout<<res<<endl;
 }


#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<memory.h>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<deque>
#include<list>
#include<numeric>
using namespace std;
string s,p;
int s1[30],p1[30],i,w,res;
bool ispr(int s1[],int p1[],int w){
    int d=0;
    for(int i=0;i<26;i++){
        if(s1[i]>p1[i]) return 0;
        d+=p1[i]-s1[i];
    }
    return d==w;
}
int main(){
int plen,slen;
    cin>>s>>p;
    slen=s.size();
    plen=p.size();
	if(plen>slen){cout<<0<<endl; return 0;}
    for(i=0;i<p.size();i++){
        if(s[i]=='?') w++; else s1[s[i]-'a']++;
        p1[p[i]-'a']++;
    }
    for(int i=0;i<=slen-plen;i++){
        if(ispr(s1,p1,w)) res++;
        if(s[i]=='?') w--;
        else s1[s[i]-'a']--;
        if(i==slen-plen) break;
		if(s[i+plen]=='?') w++;
        else s1[s[i+plen]-'a']++;
    }
    cout<<res<<endl;
}


#include<iostream>
 #include<cmath>
 #include<vector>
 #include<algorithm>
 #include<string>
 #include<memory.h>
 #include<utility>
 #include<set>
 #include<map>
 #include<sstream>
 #include<cstdio>
 #include<cstdlib>
 #include<deque>
 #include<list>
 #include<numeric>
 using namespace std;
 string s,p;
 int n,i,j,a['z'+1],res;
 vector<string> mas;
 bool isper(string s){
     int t['z'+1];
     memset(t,0,sizeof(t));
     int r=0,q=0;
     for(int i=0;i<s.length();i++)
         if(s[i]=='?')r++; else t[s[i]]++;
     if(r>=p.length()) return 1;
     for(int i='a';i<='z';i++)
         if(t[i] && a[i]) q+=min(t[i],a[i]);
     if(r+q>=p.length()) return 1;
     return 0;
 }
 int main(){
     cin>>s>>p;
	 if(p.length()>s.length()){cout<<0<<endl; return 0;}
     for(i=0;i<p.length();i++)
         a[p[i]]++;
	 for(i=0;i<s.length()-p.length();i++)
		 mas.push_back(s.substr(i,p.length()));
     for(i=0;i<mas.size();i++)
         res+=isper(mas[i]);
     cout<<res<<endl;
 }


#include<iostream>
#include<cmath>
#include<vector>
#include<algorithm>
#include<string>
#include<memory.h>
#include<utility>
#include<set>
#include<map>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<deque>
#include<list>
#include<numeric>
using namespace std;
string s,p;
int s1[30],p1[30],i,w,res;
bool ispr(int s1[],int p1[],int w){
    int d=0;
    for(int i=0;i<26;i++){
        if(s1[i]>p1[i]) return 0;
        d+=p1[i]-s1[i];
    }
    return d==w;
}
int main(){
int plen,slen;
    cin>>s>>p;
    slen=s.size();
    plen=p.size();

    for(i=0;i<p.size();i++){
        if(s[i]=='?') w++; else s1[s[i]-'a']++;
        p1[p[i]-'a']++;
    }
    for(int i=0;i<=slen-plen;i++){
        if(ispr(s1,p1,w)) res++;
        if(s[i]=='?') w--;
        else s1[s[i]-'a']--;
        if(i==slen-plen) break;
        if(s[i+plen]=='?') w++;
        else s1[s[i+plen]-'a']++;
    }
    cout<<res<<endl;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn ((int)1e5+10)

char s[Maxn],p[Maxn];
int cp[27],cs[27];

int main(){

    scanf("%s%s",s,p);

    int ls=strlen(s);
    int lp=strlen(p);

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a'+1]++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){
        if(i==0){
            for(int j=0;j<lp;j++){
                if(s[j]!='?')   cs[s[j]-'a'+1]++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){
                if(cs[j]>cp[j])good=false;
                break;
            }
            if(good)ans++;

            continue;
        }
        cs[s[i-1]-'a'+1]--;
        cs[s[i+lp-1]-'a'+1]++;

        bool good=true;
        for(int j=1;j<=26;j++){
            if(cs[j]>cp[j]){
                good=false;
                break;
            }
        }
        if(good)ans++;
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn (100010)
// #define Debug

char s[Maxn],p[Maxn];
int cp[30],cs[30];

int main(){

    scanf("%s",s);
    scanf("%s",p);

    int ls=strlen(s);
    int lp=strlen(p);

    #ifdef Debug
    puts(s); puts(p);
    printf("%d %d\n\n",ls,lp);
    #endif

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a'+1]++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){

        if(i==0){

            for(int j=0;j<lp;j++){

                if(s[j]!='?')   cs[s[j]-'a'+1]++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){

                if(cs[j]>cp[j]){

                    good=false;
                    break;
                }
            }
            if(good)ans++;

            continue;
        }

        if(s[i-1]!='?') cs[s[i-1]-'a'+1]--;
        if(s[i+lp-1]!='?')cs[s[i+lp-1]-'a'+1]++;

        bool good=true;
        for(int j=1;j<=26;j++){

            if(cs[j]>cp[j]){

                good=false;
                break;
            }
        }
        if(good)ans++;

        #ifdef Debug
        for(int a=1;a<=26;a++){
            printf("%c %d %d\n",a+'a'-1,cs[a],cp[a]);
        }
        #endif
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn (100010)

char s[Maxn],p[Maxn];
int cp[27],cs[27];

int main(){

    scanf("%s%s",s,p);

    int ls=strlen(s);
    int lp=strlen(p);

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a'+1]++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){

        if(i==0){

            for(int j=0;j<lp;j++){

                if(s[j]!='?')   cs[s[j]-'a'+1]++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){

                if(cs[j]>cp[j]){

                    good=false;
                    break;
                }
            }
            if(good)ans++;

            continue;
        }
        cs[s[i-1]-'a'+1]--;
        cs[s[i+lp-1]-'a'+1]++;

        bool good=true;
        for(int j=1;j<=26;j++){

            if(cs[j]>cp[j]){

                good=false;
                break;
            }
        }
        if(good)ans++;
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn (100010)
// #define Debug

char s[Maxn],p[Maxn];
int cp[28],cs[28];

int main(){

    scanf("%s",s);
    scanf("%s",p);

    int ls=strlen(s);
    int lp=strlen(p);

    #ifdef Debug
    puts(s); puts(p);
    printf("%d %d\n\n",ls,lp);
    #endif

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a'+1]++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){

        if(i==0){

            for(int j=0;j<lp;j++){

                if(s[j]!='?')   cs[s[j]-'a'+1]++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){

                if(cs[j]>cp[j]){

                    good=false;
                    break;
                }
            }
            if(good)ans++;

            continue;
        }
        cs[s[i-1]-'a'+1]--;
        cs[s[i+lp-1]-'a'+1]++;

        bool good=true;
        for(int j=1;j<=26;j++){

            if(cs[j]>cp[j]){

                good=false;
                break;
            }
        }
        if(good)ans++;

        #ifdef Debug
        for(int a=1;a<=26;a++){
            printf("%c %d %d\n",a+'a'-1,cs[a],cp[a]);
        }
        #endif
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn ((int)1e5+10)

char s[Maxn],p[Maxn];
int cp[27],cs[27];

int main(){

    scanf("%s%s",s,p);

    int ls=strlen(s);
    int lp=strlen(p);

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a']++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){
        if(i==0){
            for(int j=0;j<lp;j++){
                if(s[j]!='?')   cs[s[j]-'a']++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){
                if(cs[j]>cp[j])good=false;
                break;
            }
            if(good)ans++;

            continue;
        }
        cs[s[i-1]-'a']--;
        cs[s[i+lp-1]-'a']++;

        bool good=true;
        for(int j=1;j<=26;j++){
            if(cs[j]>cp[j]){
                good=false;
                break;
            }
        }
        if(good)ans++;
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn ((int)1e5+10)

char s[Maxn],p[Maxn];
int cp[27],cs[27];

int main(){

    scanf("%s%s",s,p);

    int ls=strlen(s);
    int lp=strlen(p);

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a'+1]++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){
        if(i==0){
            for(int j=0;j<lp;j++){
                if(s[j]!='?')   cs[s[j]-'a'+1]++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){
                if(cs[j]>cp[j]){
                    good=false;
                    break;
                }
            }
            if(good)ans++;

            continue;
        }
        cs[s[i-1]-'a'+1]--;
        cs[s[i+lp-1]-'a'+1]++;

        bool good=true;
        for(int j=1;j<=26;j++){
            if(cs[j]>cp[j]){
                good=false;
                break;
            }
        }
        if(good)ans++;
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn ((int)1e5+10)

char s[Maxn],p[Maxn];
int cp[27],cs[27];

int main(){

    scanf("%s%s",s,p);

    int ls=strlen(s);
    int lp=strlen(p);

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a'+1]++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){

        if(i==0){

            for(int j=0;j<lp;j++){

                if(s[j]!='?')   cs[s[j]-'a'+1]++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){

                if(cs[j]>cp[j]){

                    good=false;
                    break;
                }
            }
            if(good)ans++;

            continue;
        }
        cs[s[i-1]-'a'+1]--;
        cs[s[i+lp-1]-'a'+1]++;

        bool good=true;
        for(int j=1;j<=26;j++){

            if(cs[j]>cp[j]){

                good=false;
                break;
            }
        }
        if(good)ans++;
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main()
{
    int ls,lp,i,j,k,asc;

    char *s = malloc(100002*sizeof(char));
    char *p = malloc(100002*sizeof(char));

    scanf("%s",s);
    scanf("%s",p);

    ls = strlen(s);
    lp = strlen(p);

    if(lp>ls)   printf("0\n");
    else{

    int *sa = malloc(26*sizeof(int));
    int *pa = malloc(26*sizeof(int));

    for(i=0;i<26;i++)   pa[i]=0;

    for(i=0;i<lp;i++)
    {
        asc = p[i];
        pa[asc-97]++;
    }

    //for(i=0;i<26;i++) printf("pa[%d] = %d\n",i,pa[i]);

    int res=0;
    for(j=0;j<26;j++)   sa[j]=0;
    for(i=0;i<=ls-lp;i++)
    {
        if(i>0)     {sa[s[i-1]-97]--;sa[s[i+lp-1]-97]++;}
        else
        {
            for(j=i;j<i+lp;j++)
            {
                if(s[j]!='?'){
                asc = s[j];
                sa[asc-97]++;}
            }
        }

        for(k=0;k<26;k++)
        {
            //printf("k = %d sa = %d pa = %d\n",k,sa[k],pa[k]);
            if(sa[k] > pa[k])   {break;}
        }

        if(k==26)   res++;
    }

    printf("%d\n",res);
    }

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn (100010)

char s[Maxn],p[Maxn];
int cp[27],cs[27];

int main(){

    scanf("%s",s);
    scanf("%s",p)

    int ls=strlen(s);
    int lp=strlen(p);

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a'+1]++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){

        if(i==0){

            for(int j=0;j<lp;j++){

                if(s[j]!='?')   cs[s[j]-'a'+1]++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){

                if(cs[j]>cp[j]){

                    good=false;
                    break;
                }
            }
            if(good)ans++;

            continue;
        }
        cs[s[i-1]-'a'+1]--;
        cs[s[i+lp-1]-'a'+1]++;

        bool good=true;
        for(int j=1;j<=26;j++){

            if(cs[j]>cp[j]){

                good=false;
                break;
            }
        }
        if(good)ans++;
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn (100010)

char s[Maxn],p[Maxn];
int cp[27],cs[27];

int main(){

    scanf("%s",s);
    scanf("%s",p);

    int ls=strlen(s);
    int lp=strlen(p);

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    for(int i=0;i<lp;i++)   cp[p[i]-'a'+1]++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){

        if(i==0){

            for(int j=0;j<lp;j++){

                if(s[j]!='?')   cs[s[j]-'a'+1]++;
            }

            bool good=true;
            for(int j=1;j<=26;j++){

                if(cs[j]>cp[j]){

                    good=false;
                    break;
                }
            }
            if(good)ans++;

            continue;
        }
        cs[s[i-1]-'a'+1]--;
        cs[s[i+lp-1]-'a'+1]++;

        bool good=true;
        for(int j=1;j<=26;j++){

            if(cs[j]>cp[j]){

                good=false;
                break;
            }
        }
        if(good)ans++;
    }

    printf("%d\n",ans);

    return 0;
}


/*
きっと生きていることに意味なんてないのよ、でも生き続けることで面白いことを见つけられるかもよ。あなたがあの花を见つけたように、私があなたを见つけたように。
*/

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
using namespace std;

#define Maxn ((int)1e5+10)

char s[Maxn],p[Maxn];

int main(){

    scanf("%s%s",s,p);

    int ls=strlen(s);
    int lp=strlen(p);

    if(lp>ls){
        printf("0\n");
        return 0;
    }

    int cp[27],cs[27];

    memset(cp,0,sizeof(cp));
    memset(cs,0,sizeof(cs));

    for(int i=0;i<lp;i++)   cp[p[i]-'a']++;

    int ans=0;
    for(int i=0;i<=ls-lp;i++){
        if(i==0){
            for(int j=0;j<lp;j++){
                if(s[j]!='?')   cs[s[j]-'a']++;
            }
            continue;
        }
        cs[s[i-1]-'a']--;
        cs[s[i+lp-1]-'a']++;

        bool good=true;
        for(int j=1;j<=26;j++){
            if(cs[j]>cp[j]){
                good=false;
                break;
            }
        }

        if(good)ans++;
    }

    printf("%d\n",ans);

    return 0;
}


#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
#define maxn 1111111
using namespace std;
char str[maxn],p[maxn];
int vis[310000];
int f[301000];
int main()
{
	int i, j,len1,len2;
    scanf("%s %s",str,p);
	len1 = strlen(str),len2 = strlen(p);
	if(len2>len1)
	{
		printf("0\n");
		return 0;
	}
	memset(vis,0,sizeof(vis));
	memset(f,0,sizeof(f));
	for(i=0;i<len2;i++)
	{
		vis[p[i]-'a']++;
	}
	for(i=0;i<len2-1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
	}
	int sum = 0;
	for(i=len2-1;i<len1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
		for(j=0;j<=25;j++)
		{
			if(f[j]>vis[j]) break;
		}
		//if(i==3) printf("%d %d %d\n",j,f[j],vis[j]);
	//	if(j>25) printf("%d\n",i);
		if(j>25) sum++;
	//	if(i-len2+1<0) {printf("-1\n");return 0;}
		f[str[i-len2+1]-'a']--;

	}
	printf("%d\n",sum);

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
#define maxn 1111111
using namespace std;
char str[maxn],p[maxn];
int vis[310000];
int f[301000];
int main()
{
	int i, j,len1,len2, flag = 0;
    scanf("%s %s",str,p);
	len1 = strlen(str),len2 = strlen(p);
	if(len2>len1)
	{
		printf("0\n");
		return 0;
	}
	memset(vis,0,sizeof(vis));
	memset(f,0,sizeof(f));
	for(i=0;i<len2;i++)
	{
		vis[p[i]-'a']++;
	}
	for(i=0;i<len2-1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
	}
	int sum = 0;
	for(i=len2-1;i<len1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
		for(j=0;j<=25;j++)
		{
			if(f[j]>vis[j])
				break;
		}

		if(j>25) sum++;
		if(str[i-len2+1]-'a' >= 0)
			f[str[i-len2+1]-'a']--;

	}
	printf("%d\n",sum);

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
#define maxn 1111111
using namespace std;
char str[maxn],p[maxn];
int vis[310000];
int f[301000];
int main()
{
	int i, j,len1,len2;
    scanf("%s %s",str,p);
	len1 = strlen(str),len2 = strlen(p);
	if(len2>len1)
	{
		printf("0\n");
		return 0;
	}
	memset(vis,0,sizeof(vis));
	memset(f,0,sizeof(f));
	for(i=0;i<len2;i++)
	{
		vis[p[i]-'a']++;
	}
	for(i=0;i<len2-1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
	}
	int sum = 0;
	return 0;
	for(i=len2-1;i<len1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
		for(j=0;j<=25;j++)
		{
			if(f[j]>vis[j]) break;
		}
		if(j>25) sum++;
		f[str[i-len2+1]-'a']--;

	}
	printf("%d\n",sum);

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
#define maxn 1111111
using namespace std;
char str[maxn],p[maxn];
int vis[310000];
int f[301000];
int main()
{
	int i, j,len1,len2, flag = 0;
    scanf("%s %s",str,p);
	len1 = strlen(str),len2 = strlen(p);
	if(len2>len1)
	{
		printf("0\n");
		return 0;
	}
	memset(vis,0,sizeof(vis));
	memset(f,0,sizeof(f));
	for(i=0;i<len2;i++)
	{
		vis[p[i]-'a']++;
	}
	for(i=0;i<len2-1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
	}
	int sum = 0;
	for(i=len2-1;i<len1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
		for(j=0;j<=25;j++)
		{
			if(f[j]>vis[j])
				break;
		}

		if(j>25) sum++;
		/*f[str[i-len2+1]-'a']--;*/

	}
	printf("%d\n",sum);

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
#define maxn 1111111
using namespace std;
char str[maxn],p[maxn];
int vis[310000];
int f[301000];
int main()
{
	int i, j,len1,len2, flag = 0;
    scanf("%s %s",str,p);
	len1 = strlen(str),len2 = strlen(p);
	if(len2>len1)
	{
		printf("0\n");
		return 0;
	}
	memset(vis,0,sizeof(vis));
	memset(f,0,sizeof(f));
	for(i=0;i<len2;i++)
	{
		vis[p[i]-'a']++;
	}
	for(i=0;i<len2-1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
	}
	int sum = 0;
	for(i=len2-1;i<len1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
		for(j=0;j<=25;j++)
		{
			if(f[j]>vis[j])
				break;
		}
		/*
		if(j>25) sum++;
		f[str[i-len2+1]-'a']--;*/

	}
	printf("%d\n",sum);

	return 0;
}


#include<stdio.h>
#include<string.h>
#include<string>
#include<algorithm>
#include<iostream>
#define maxn 1111111
using namespace std;
char str[maxn],p[maxn];
int vis[310000];
int f[301000];
int main()
{
	printf("%d", '?');
	int i, j,len1,len2, flag = 0;
    scanf("%s %s",str,p);
	len1 = strlen(str),len2 = strlen(p);
	if(len2>len1)
	{
		printf("0\n");
		return 0;
	}
	memset(vis,0,sizeof(vis));
	memset(f,0,sizeof(f));
	for(i=0;i<len2;i++)
	{
		vis[p[i]-'a']++;
	}
	for(i=0;i<len2-1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
	}
	int sum = 0;
	for(i=len2-1;i<len1;i++)
	{
		if(str[i]=='?') f[100]++;
		else f[str[i]-'a']++;
		for(j=0;j<=25;j++)
		{
			if(f[j]>vis[j])
				break;
		}

		if(j>25) sum++;
		if(f[i]!= '?')
			f[str[i-len2+1]-'a']--;

	}
	printf("%d\n",sum);

	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int arr1[26], arr2[26], sizs, sizp, sol=0;
    string p, s;
    cin>>s>>p; sizs=s.size(); sizp=p.size();

    if(sizp>sizs) { cout<<0; return 0; }

    memset(arr1,0,(sizeof(int)*26));
    for(int i=0;i<sizp;i++) arr1[(int)p[i]-(int)'a']++;

    for(int i=0;i<sizs;i++){
        if((i+sizp-1)>=sizs) break;
        int c1=0, c2=0;
        memcpy(arr2,arr1,(sizeof(int)*26));
        for(int k=i;k<=(i+sizp-1);k++){
            if(s[k]=='?') c1++;
            else arr2[(int)s[k]-(int)'a']--;
        }

        for(int i=0;i<26;i++){
            if(arr2[i]>=0) c2+=arr2[i];
            else { c2=-1; break; }
        }

        if((c2!=-1)&&(c1==c2)) sol++;
    }

    cout<<sol;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
    int arr1[26], arr2[26], sizs, sizp, sol=0; memset(arr1,0,(sizeof(int)*26));
    string p, s;
    cin>>s>>p; sizs=s.size(); sizp=p.size();

    if(sizp>sizs) { cout<<0; return 0; }

    for(int i=0;i<sizp;i++) arr1[(int)p[i]-(int)'a']++;

    for(int i=0;i<sizs;i++){
        for(int j=i+sizp-1;j<sizs;j++){
            int c1=0, c2=0;
            memcpy(arr2,arr1,sizeof(int)*26);
            for(int k=i;k<=j;k++){
                //cout<<s[k];
                if(s[k]=='?') c1++;
                else arr2[(int)s[k]-(int)'a']--;
            }

            for(int i=0;i<26;i++){
                if(arr2[i]>=0) c2+=arr2[i];
                else { c2=-1; break; }
            }

            //cout<<"  "<<c1<<"  "<<c2<<endl;
            if((c2!=-1)&&(c1==c2)&&(c1>0)) sol++;
        }
    }

    cout<<sol;
    return 0;
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

ll inv(ll n, ll a) // a*x%n==1
{
	ll s, s1, s2, t, t1, t2, r, r1, r2;
	r1 = a, r2 = n, s1 = 1, s2 = 0, t1 = 0, t2 = 1;
	while (r2 > 0)
	{
		ll q = r1 / r2;
		r = r1 - q*r2;
		r1 = r2;
		r2 = r;
		s = s1 - q*s2;
		s1 = s2;
		s2 = s;
		t = t1 - q*t2;
		t1 = t2;
		t2 = t;
	}
	if (r1 != 1)return -1;
	return (s1+n)%n;
}
int n,m;
bitset<200001> prime,chk;
Vi v[200001],vv[200001];
int d[200001];
int go(int x)
{
	if(~d[x])return d[x];
	int t=v[x].size();
	int r=0;
	for(int next:vv[x])
		r=max(r,go(next));
	return d[x]=r+t;
}
int pre=-1;
void track(int x)
{
	if(!v[x].empty())
	{
		if(!~pre) printf("%d ",v[x][0]);
		else
		{
			int t=inv(m,pre);
			t=(t*v[x][0])%m;
			printf("%d ",t);
		}
		pre=v[x][0];
		fup(i,1,(int)v[x].size()-1,1)
		{
			int t=inv(m/x,pre/x);
			t=(t*(v[x][i]/x))%m;
			printf("%d ",t);
			pre=v[x][i];
		}
	}
	int t1=0,t2=-1;
	for(int next:vv[x])
	{
		int t=go(next);
		if(t>t1)
		{
			t1=t;
			t2=next;
		}
	}
	if(t2!=-1)track(t2);
}
int main() {
	MEM_1(d);
	prime.set();
	prime[0]=prime[1]=0;
	fup(i,2,100000,1)
	{
		if(!prime[i])continue;
		fup(j,i+i,200000,i)
			prime[j]=0;
	}
	scanf("%d%d",&n,&m);
	fup(i,1,n,1)
	{
		int x;
		scanf("%d",&x);
		chk[x]=1;
	}
	fup(i,1,m-1,1)
	{
		if(!chk[i])v[gcd(m,i)].pb(i);
	}
	fup(i,1,m-1,1)
	{
		fup(j,i+i,m,i)vv[i].pb(j);
	}
	printf("%d\n",go(1)+(!chk[0]));
	track(1);
	if(!chk[0])puts("0");
}


#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<ld, ld> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<int,int,int,int> iiii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

ll inv(ll n, ll a) // a*x%n==1
{
	ll s, s1, s2, t, t1, t2, r, r1, r2;
	r1 = a, r2 = n, s1 = 1, s2 = 0, t1 = 0, t2 = 1;
	while (r2 > 0)
	{
		ll q = r1 / r2;
		r = r1 - q*r2;
		r1 = r2;
		r2 = r;
		s = s1 - q*s2;
		s1 = s2;
		s2 = s;
		t = t1 - q*t2;
		t1 = t2;
		t2 = t;
	}
	if (r1 != 1)return -1;
	return (s1+n)%n;
}
int n,m;
bitset<200001> prime,chk;
Vi v[200001],vv[200001];
int d[200001];
int go(int x)
{
	if(~d[x])return d[x];
	int t=v[x].size();
	int r=0;
	for(int next:vv[x])
		r=max(r,go(next));
	return d[x]=r+t;
}
int pre=-1;
void track(int x)
{
	if(!v[x].empty())
	{
		if(!~pre) printf("%d ",v[x][0]);
		else
		{
			int g=gcd(m,pre);
			int t=inv(m/g,pre/g);
			t=(1LL*t*(v[x][0]/g))%(m/g);
			printf("%d ",t);
		}
		pre=v[x][0];
		fup(i,1,(int)v[x].size()-1,1)
		{
			int t=inv(m/x,pre/x);
			t=(1LL*t*(v[x][i]/x))%m;
			printf("%d ",t);
			pre=v[x][i];
		}
	}
	int t1=0,t2=-1;
	for(int next:vv[x])
	{
		int t=go(next);
		if(t>t1)
		{
			t1=t;
			t2=next;
		}
	}
	if(t2!=-1)track(t2);
}
int main() {
	MEM_1(d);
	prime.set();
	prime[0]=prime[1]=0;
	fup(i,2,100000,1)
	{
		if(!prime[i])continue;
		fup(j,i+i,200000,i)
			prime[j]=0;
	}
	scanf("%d%d",&n,&m);
	fup(i,1,n,1)
	{
		int x;
		scanf("%d",&x);
		chk[x]=1;
	}
	fup(i,1,m-1,1)
	{
		if(!chk[i])v[gcd(m,i)].pb(i);
	}
	fup(i,1,m-1,1)
	{
		fup(j,i+i,m,i)vv[i].pb(j);
	}
	printf("%d\n",go(1)+(!chk[0]));
	track(1);
	if(!chk[0])puts("0");
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <bitset>

using namespace std;

#define FOR(a, b) for (int a = 0; a < (b); ++a)
#define clr(a) memset(a, 0, sizeof(a))
#define pb push_back
#define forab(i, a, b) for(int i = int(a); i < int(b); ++i)
#define forba(i, b, a) for(int i = int(b) - 1; i >= int(a); --i)
#define forn(i, n) forab(i, 0, n)
#ifdef LOCAL
#define debug(a) cerr << #a << ": " << a << '\n';
#else
#define debug(a)
#endif

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;
const ld PI = acos(-1.0L);
const int MAXN = 2e5 + 100;
const int MAXD = 1000;

bool f[MAXN];
int g[MAXN];
int dp[MAXN];
int pr[MAXN];
int inv[MAXN];
vector<int> r[MAXN];

ll gcd (ll a, ll b, ll & x, ll & y) {
    if (a == 0) {
        x = 0; y = 1;
        return b;
    }
    ll x1, y1;
    ll d = gcd (b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int main() {
#ifdef LOCAL
    freopen("c.in", "r", stdin);
    //freopen("", "w", stdout);
    //freopen("", "w", stderr);
#endif
    int n, m;
    cin.sync_with_stdio(0);
    cin >> n >> m;
    forn(i, n) {
        int x;
        cin >> x;
        if (x == 0)
            x += m;
        f[x] = true;
    }
    vector<int> divs;
    for (int i = 1; i <= m; ++i) {
        ll x = 0, y = 0;
        g[i] = gcd(i, m, x, y);
        x %= m;
        inv[i] = x;
        if (x < 0)
            inv[i] = (m + x) % m;
        if (!f[i])
            r[g[i]].push_back(i);
        if (g[i] == i) {
            divs.pb(i);
        }
    }
    int k = divs.size();
    for (int i = k - 1; i >= 0; --i) {
        int d = divs[i];
        dp[d] = 0;
        pr[d] = -1;
        for (int j = k - 1; j > i; --j) {
            int q = divs[j];
            if (q % d == 0) {
                if (dp[d] < dp[q]) {
                    dp[d] = dp[q];
                    pr[d] = q;
                }
            }
        }
        dp[d] += r[d].size();
    }
    cout << dp[1] << '\n';
    vector<int> ans = {1};
    for (int g = 1; g != -1; g = pr[g]) {
        for (auto x : r[g])
            ans.pb(x);
        vector<int> cur = r[g];
        forn(i, cur.size()) {
            cur[i] /= g;
        }
    }
    assert(ans.size() == dp[1] + 1);
    for (int i = 1; i < ans.size(); ++i) {
        int a = ans[i];
        int b = ans[i - 1];
        ll mul = g[a] / g[b];

        a /= g[a];
        mul = (((ll)inv[b]) * mul) % m * ((ll)a) % m;
        cout << mul << ' ';
    }

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
#include <bitset>

using namespace std;

#define FOR(a, b) for (int a = 0; a < (b); ++a)
#define clr(a) memset(a, 0, sizeof(a))
#define pb push_back
#define forab(i, a, b) for(int i = int(a); i < int(b); ++i)
#define forba(i, b, a) for(int i = int(b) - 1; i >= int(a); --i)
#define forn(i, n) forab(i, 0, n)
#ifdef LOCAL
#define debug(a) cerr << #a << ": " << a << '\n';
#else
#define debug(a)
#endif

typedef long long ll;
typedef long double ld;

const int INF = 1e9;
const ld EPS = 1e-8;
const ld PI = acos(-1.0L);
const int MAXN = 2e5 + 100;
const int MAXD = 1000;

bool f[MAXN];
int g[MAXN];
int dp[MAXN];
int pr[MAXN];
int inv[MAXN];
vector<int> r[MAXN];

int gcd (int a, int b, int & x, int & y) {
    if (a == 0) {
        x = 0; y = 1;
        return b;
    }
    int x1, y1;
    int d = gcd (b%a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

int main() {
#ifdef LOCAL
    freopen("c.in", "r", stdin);
    //freopen("", "w", stdout);
    //freopen("", "w", stderr);
#endif
    int n, m;
    cin.sync_with_stdio(0);
    cin >> n >> m;
    forn(i, n) {
        int x;
        cin >> x;
        f[x] = true;
    }
    vector<int> divs;
    for (int i = 1; i <= m; ++i) {
        int x = 0, y = 0;
        g[i] = gcd(i, m, x, y);
        x %= m;
        inv[i] = x;
        if (x < 0)
            inv[i] = (m + x) % m;
        if (!f[i])
            r[g[i]].push_back(i);
        if (g[i] == i) {
            divs.pb(i);
        }
    }
    int k = divs.size();
    for (int i = k - 1; i >= 0; --i) {
        int d = divs[i];
        dp[d] = 0;
        pr[d] = -1;
        for (int j = k - 1; j > i; --j) {
            int q = divs[j];
            if (q % d == 0) {
                if (dp[d] < dp[q]) {
                    dp[d] = dp[q];
                    pr[d] = q;
                }
            }
        }
        dp[d] += r[d].size();
    }
    cout << dp[1] << '\n';
    vector<int> ans = {1};
    for (int g = 1; g != -1; g = pr[g]) {
        for (auto x : r[g])
            ans.pb(x);
        vector<int> cur = r[g];
        forn(i, cur.size()) {
            cur[i] /= g;
        }
    }
    assert(ans.size() == dp[1] + 1);
    for (int i = 1; i < ans.size(); ++i) {
        int a = ans[i];
        int b = ans[i - 1];
        int mul = g[a] / g[b];

        a /= g[a];
        mul = (inv[b] * mul) % m * a % m;
        cout << mul << ' ';
    }

    return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long globalInverse = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}
		long long curMul = 1;
		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back(((globalInverse * m / cur) % m * i) % m);
						firstAdd = false;
					}
					else {
						nums.push_back((((binpow(curMul, phi - 1, cur) * i)) % m) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}
		globalInverse *= binpow(curMul, phi - 1, cur);
		globalInverse %= cur;
		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long curMul = 1;
	long long lastPhi = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back(((binpow(curMul % cur, phi - 1, cur) * lastMult) % m * i) % m);
						firstAdd = false;
					}
					else {
						nums.push_back((((binpow(curMul, phi - 1, cur) * i)) % m) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}

		lastPhi = phi;

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long curMul = 1;
	long long firstPhi = 0;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		if (firstPhi == 0) {
			firstPhi = phi;
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						if (curMul % cur != i) {
							nums.push_back((((binpow(curMul, firstPhi - 1, m) * lastMult) % m) * i) % m);
						}
						else {
							nums.push_back((((lastMult) % m)) % m);
						}

						firstAdd = false;
					}
					else {
						nums.push_back(((binpow(curMul, firstPhi - 1, m) * i)) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long curMul = 1;
	long long firstPhi = 0;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		if (firstPhi == 0) {
			firstPhi = phi;
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back((((binpow(curMul, firstPhi - 1, m) * lastMult) % m) * i) % m);
						firstAdd = false;
					}
					else {
						nums.push_back(((binpow(curMul, firstPhi - 1, m) * i)) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long curMul = 1;
	long long firstPhi = 0;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		if (firstPhi == 0) {
			firstPhi = phi;
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						if (curMul % cur != i) {
							nums.push_back((((binpow(curMul % cur, phi - 1, cur) * lastMult) % m) * i) % m);
						}
						else {
							nums.push_back((((lastMult) % m)) % m);
						}

						firstAdd = false;
					}
					else {
						nums.push_back(((binpow(curMul, phi - 1, cur) * i)) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long curMul = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back((((binpow(curMul * m / (cur * lastMult), phi - 1, cur) * lastMult) % m) * i) % m);
						firstAdd = false;
					}
					else {
						nums.push_back(((binpow(curMul, phi - 1, cur) * i)) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long curMul = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back((((binpow(curMul, phi - 1, cur) * lastMult) % m) * i) % m);
						firstAdd = false;
					}
					else {
						nums.push_back(((binpow(curMul, phi - 1, cur) * i)) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}
		long long curMul = 1;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					long long nextMul = i;

					if (nums.size() == 0) {
						nums.push_back(m / cur * nextMul);
					}
					else {
						nums.push_back((((binpow(curMul, phi - 1, cur) * nextMul) % m) * (m / cur)) % m);
					}
					curMul = nextMul;
					curAdded++;
				}
			}
		}
		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long curMul = 1;
	long long lastPhi = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back((((binpow(curMul, lastPhi - 1, cur * lastMult) * lastMult) % m) * i) % m);
						firstAdd = false;
					}
					else {
						nums.push_back(((binpow(curMul, phi - 1, cur) * i)) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}

		lastPhi = phi;

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

void gen() {
	ofstream cout("output.txt");
	long long ans[] = { 3761, 27161, 1181, 2231, 16903, 24623, 22293, 7517, 23899, 3337, 8818, 13582, 11444, 27528, 2940 };
	vector<long long> good;
	long long cur = 1;
	for (int i = 0; i < 15; i++) {
		cur *= ans[i];
		cur %= 30030;
		good.push_back(cur);
	}
	for (int i = 0; i < 30030; i++) {
		bool ok = true;
		for (int j = 0; j < 15; j++) {
			if (good[j] == i) {
				ok = false;
				break;
			}
		}
		if (ok) {
			cout << i << " ";
		}
	}
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	//gen();

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long curMul = 1;
	long long firstPhi = 0;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		if (firstPhi == 0) {
			firstPhi = phi;
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						if (curMul % cur != i) {
							nums.push_back((((binpow(curMul % cur, phi - 1, cur) * lastMult) % m) * i) % m);
						}
						else {
							nums.push_back((((lastMult) % m)) % m);
						}

						firstAdd = false;
						lastMult = 1;
					}
					else {
						nums.push_back(((binpow(curMul, phi - 1, cur) * i)) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult *= divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

bool validate(vector<long long> &ans) {
	long long cur = 1;
	set<long long> st;
	for (int i = 0; i < ans.size(); i++) {
		cur *= ans[i];
		cur %= m;
		if (isForbid[cur]) {
			return false;
		}
		if (st.find(cur) != st.end()) {
			return false;
		}
		st.insert(cur);
	}
	return true;
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long lastMult = 1;
	long long globalInverse = 1;
	long long curMul = 1;
	long long lastPhi = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}

		bool firstAdd = true;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (firstAdd) {
						nums.push_back(((binpow(curMul, lastPhi - 1, cur * lastMult) * lastMult) % m * i) % m);
						firstAdd = false;
					}
					else {
						nums.push_back((((binpow(curMul, phi - 1, cur) * i)) % m) % m);
					}
					curMul = i;
					curAdded++;
				}
			}
		}
		globalInverse *= binpow(curMul, phi - 1, cur);
		globalInverse %= cur;

		lastPhi = phi;

		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				lastMult = divisors[i];
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	//cout << validate(nums) << endl;

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}


#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <fstream>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <bitset>
#include <memory.h>

using namespace std;

const long long maxn = 222222;
vector<long long> forbid;
bool isForbid[maxn];
long long n, m;
vector<long long> divisors;

long long gcd(long long a, long long b) {
	if (b == 0) {
		return a;
	}
	return gcd(b, a % b);
}

long long binpow(long long a, long long b, long long mod) {
	if (b == 0) {
		return 1;
	}
	else if (b % 2 == 0) {
		return binpow((a * a) % mod, b / 2, mod);
	}
	else {
		return (a * binpow(a, b - 1, mod)) % mod;
	}
}

long long f[maxn];

long long go(long long p) {
	if (f[p] != -1) {
		return f[p];
	}

	long long cnt = 0;
	for (long long i = 1; i < p; i++) {
		if (gcd(i, p) == 1) {
			long long want = m / p * i;
			if (!isForbid[want]) {
				cnt++;
			}
		}
	}
	long long ans = 0;

	for (long long i = 0; i < divisors.size(); i++) {
		if (p % divisors[i] != 0) {
			continue;
		}
		long long next = p / divisors[i];

		ans = max(ans, go(next));
	}

	ans += cnt;

	f[p] = ans;
	return f[p];
}

int main() {
	ios_base::sync_with_stdio(false);
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");

	memset(f, -1, sizeof(f));
	cin >> n >> m;
	for (long long i = 0; i < n; i++) {
		long long q;
		cin >> q;
		forbid.push_back(q);
		isForbid[q] = true;
	}

	long long temp = m;
	for (long long i = 2; i * i <= temp; i++) {
		if (temp % i == 0) {
			divisors.push_back(i);
			while (temp % i == 0) {
				temp /= i;
			}
		}
	}
	if (temp > 1) {
		divisors.push_back(temp);
	}

	long long ans = go(m);

	vector<long long> nums;

	long long cur = m;
	long long saveInverse = 1;
	while (cur > 1) {
		long long curAdded = 0;
		long long phi = 0;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				phi++;
			}
		}
		long long curMul = 1;
		long long curInv;
		for (long long i = 1; i < cur; i++) {
			if (gcd(i, cur) == 1) {
				if (!isForbid[m / cur * i]) {
					if (nums.size() == 0) {
						nums.push_back(m / cur * i);
					}
					else {
						nums.push_back((saveInverse * (((binpow(curMul, phi - 1, cur) * i) % m) * (m / cur)) % m) % m);
					}
					curInv = binpow(i, phi - 1, cur);
					curMul = i;
					curAdded++;
				}
			}
		}
		saveInverse = (saveInverse * curInv) % cur;
		for (long long i = 0; i < divisors.size(); i++) {
			if (cur % divisors[i] != 0) {
				continue;
			}
			long long next = cur / divisors[i];
			if (f[cur] == curAdded + f[next]) {
				cur = next;
				break;
			}
		}
	}

	if (!isForbid[0]) {
		ans++;
		nums.push_back(0);
	}

	cout << ans << endl;
	for (long long i = 0; i < nums.size(); i++) {
		cout << nums[i] << " ";
	}

	//system("pause");
	return 0;
}