[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]:
declare dig with integer x as argument, returning integer
    create integer res with res = 0
    while x is true
        increment res
        set x to x / 7
    end of the block
    return maximum of 1 and res from function
end of the block
declare getmask with integers x, dig as arguments, returning integer
    create integer mask with mask = 0
    while decrement dig is true
        create integer cm with cm = ( 1 bitshift left ( x % 7 ) )
        if ( mask bitwise and cm ), return -1 from function
        set mask to mask bitwise or cm
        set x to x / 7
    end of the block
    return mask from function
end of the block
create integer array msk1 with size 10000000
create integer array msk2 with size 10000000
define the main function
    create integers n, m
    read n read m
    create integer d1 with d1 = result of run dig with n - 1 as argument
    create integer d2 with d2 = result of run dig with m - 1 as argument
    if d1 + d2 is greater than 7
        print 0 print newline
        return to indicate successful execution
    end of the block
    for i = 0 to n exclusive, set msk1[i] to result of run getmask with i, d1 as arguments
    for i = 0 to m exclusive, set msk2[i] to result of run getmask with i, d2 as arguments
    create integer ans with ans = 0
    for i = 0 to n exclusive
        for j = 0 to m exclusive
            if msk1[i] is less than 0 or msk2[j] is less than 0, break current loop iteration
            if ( msk1[i] bitwise and msk2[j] ) is 0, increment ans
        end of the block
    end of the block
    print ans print newline
    return to indicate successful execution
end of the block

[CODE]:

int dig(int x) {
    int res = 0;
    while (x) {
        res++;
        x /= 7;
    }
    return max(1, res);
}
int getmask(int x, int dig) {
    int mask = 0;
    while (dig--) {
        int cm = (1 << (x % 7));
        if ((mask & cm)) return -1;
        mask |= cm;
        x /= 7;
    }
    return mask;
}
int msk1[10000000];
int msk2[10000000];
int main() {
    int n, m;
    cin >> n >> m;
    int d1 = dig(n - 1);
    int d2 = dig(m - 1);
    if (d1 + d2 > 7) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 0; i < n; i++) { msk1[i] = getmask(i, d1); }
    for (int i = 0; i < m; i++) { msk2[i] = getmask(i, d2); }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (msk1[i] < 0 || msk2[j] < 0) continue;
            if ((msk1[i] & msk2[j]) == 0) { ans++; }
        }
    }
    cout << ans << endl;
    return 0;
}