[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]:
create integers n, m
declare log7 with integer x as argument
    create integer res with res = 0
    if x is 0, return 1 from function
    while x is true
        set x to x / 7
        increment res
    end of the block
    return res from function
end of the block
declare base10 with integer x as argument, returning integer
    create integers spow, res with spow = 1, res = 0
    while x is rue
        increment res by spow * ( x % 10 )
        set x to x / 10
        set spow to spow * 7
    end of the block
    return res from function
end of the block
create map vis from pair of ( integer and integer ) to boolean
create integer ans
declare solve with integer sz as argument, returning void
    create integer vector p
    for i = 0 to 7 exclusive, add element i to end of p
    start loop
        create integers x, y
        set x to y to 0
        for i = 0 to result of run log7 with n as argument exclusive
            set x to x * 10
            increment x by p[i]
        end of the block
        for i = result of run log7 with n as argument to sz exclusive
            set y to y * 10
            increment y by p[i]
        end of the block
        if n is greater than or equal to result of run base10 with x as argument and m is greater than or equal to result of run base10 with y as argument
            if not vis[ make pair from ( x, y ) ]
                increment ans
                set vis[make pair from ( x, y ) ] to true
            end of the block
        end of the block
    while result of run next_permutation with beginning of p, end of p as arguments is true
end of the block
define the main function
    read n read m
    decrement n
    decrement m
    create integer sz with sz = result of run log7 with n as argument + result of run log7 with m as argument
    if sz is greater than 7
        print 0 print newline
        return to indicate successful execution
    end of the block
    run solve with sz as argument
    print ans print newline
    return to indicate successful execution
end of the block

[CODE]:

int n, m;
int log7(int x) {
    int res = 0;
    if (x == 0) return 1;
    while (x) {
        x /= 7;
        res++;
    }
    return res;
}
int base10(int x) {
    int spow = 1, res = 0;
    while (x) {
        res += spow * (x % 10);
        x /= 10;
        spow *= 7;
    }
    return res;
}
map<pair<int, int>, bool> vis;
int ans;
void solve(int sz) {
    vector<int> p;
    for (int i = 0; i < 7; i++) p.push_back(i);
    do {
        int x, y;
        x = y = 0;
        for (int i = 0; i < log7(n); i++) {
            x *= 10;
            x += p[i];
        }
        for (int i = log7(n); i < sz; i++) {
            y *= 10;
            y += p[i];
        }
        if (n >= base10(x) && m >= base10(y)) {
            if (!vis[make_pair(x, y)]) {
                ans++;
                vis[make_pair(x, y)] = true;
            }
        }
    } while (next_permutation(p.begin(), p.end()));
}
int main() {
    cin >> n >> m;
    n--;
    m--;
    int sz = log7(n) + log7(m);
    if (sz > 7) {
        cout << 0 << endl;
        return 0;
    }
    solve(sz);
    cout << ans << endl;
    return 0;
}