[TASK]:
You will be given lines of pseudocode, your task is to write the corresponding C++ code. The pseudocode will provide detailed description of the c++ code line by line. The pseudocode is garanteed to be correct and complete.

[INSTRUCTION]:
The following libraries are already included in the code.
```cpp
#include <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <fstream>
#include <climits>
#include <cassert>
#include <iomanip>
#include <sstream>
#include <bitset>
using namespace std;
```
Do not include them in your code again. Please surround your code with ```cpp and ``` markers. Note that the code should correspond to the pseudocode line by line.

[PSEUDOCODE]:
let n, m be integers
used = bool array of size 7
counter, digitn, digitm = integers with counter = 0, digitn = 0, and digitm = 0
in the function checkh that takes integer x and return bool
    if x is greater than or equal to 0 and x is less than n, then return true
    return false
end of the block
in the function checkm that takes integer x and return bool
    if x is greater than or equal to 0 and x is less than m, then return true
    return false
end of the block
in the function permutem that takes integers a, number
    if number is equal to digitm
        if call checkm with argument a is true, then increment counter
        return
    end of the block
    for i = 0 to 7 exclusive
        if not used[i]
            set used[i] to true
            call permutem with arguments a * 7 + i, number + 1
            set used[i] to false
        end of the block
end of the block
in the function permuteh that takes integers a, number
    if number is equal to digitn
        if call checkh with argument a is true, then call permutem with arguments 0, 0
        return
    end of the block
    for i = 0 to 7 exclusive
        if not used[i]
            set used[i] to true
            call permuteh with arguments a * 7 + i, number + 1
            set used[i] to false
        end of the block
end of the block
define the main function
    read n, m
    faken = integer = n - 1, fakem = integer = m - 1
    if n is equal to 1, then assign 1 to faken
    if m is equal to 1, then assign 1 to fakem
    while faken is greater than 0
        assign faken / 7 to faken
        increment digitn
    end of the block
    while fakem is greater than 0
        assign fakem / 7 to fakem
        increment digitm
    end of the block
    if the sum of digitn and digitm is greater than 7
        output 0
    else
        call permuteh with arguments 0, 0
        output counter
    end of the block
    return to indicate successful execution
end of the block

[CODE]:

int n, m;
bool used[7];
int counter = 0, digitn = 0, digitm = 0;
bool checkh(int x) {
    if (x >= 0 && x < n) return true;
    return false;
}
bool checkm(int x) {
    if (x >= 0 && x < m) return true;
    return false;
}
void permutem(int a, int number) {
    if (number == digitm) {
        if (checkm(a)) counter++;
        return;
    }
    for (int i = 0; i < 7; i++)
        if (!used[i]) {
            used[i] = true;
            permutem(a * 7 + i, number + 1);
            used[i] = false;
        }
}
void permuteh(int a, int number) {
    if (number == digitn) {
        if (checkh(a)) permutem(0, 0);
        return;
    }
    for (int i = 0; i < 7; i++)
        if (!used[i]) {
            used[i] = true;
            permuteh(a * 7 + i, number + 1);
            used[i] = false;
        }
}
int main() {
    cin >> n >> m;
    int faken = n - 1, fakem = m - 1;
    if (n == 1) faken = 1;
    if (m == 1) fakem = 1;
    while (faken > 0) {
        faken /= 7;
        digitn++;
    }
    while (fakem > 0) {
        fakem /= 7;
        digitm++;
    }
    if (digitn + digitm > 7)
        cout << 0 << "\n";
    else {
        permuteh(0, 0);
        cout << counter << "\n";
    }
    return 0;
}