[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]:
SevenPows = integer array which includes = 0, 7, 49, 343, 2401, 16807, 117649
visited = bool array of size 8
N, M, dh, dm = integers
in the function Judge that includes integers h and m and returns bool
    fill from visited to visited + 8 with false
    for i = 0 to dm exclusive
        if visited[m modulo 7], return false
        visited[m modulo 7] = true
        m = m / 7
    end of the block
    for i = 0 to dh exclusiv
        if visited[h modulo 7], return false
        visited[h modulo 7] = true
        h = h / 7
    end of the block
    return true
end of the block
define the main function
    i, j = integer
    read N, M
    for i = 0 to 6
        if N <= SevenPows[i]
            dh = i
            break loop
        end of the block
    end of the block
    if i is 7
        print 0
        return to indicate successful execution
    end of the block
    for i = 0 to 6
        if M <= SevenPows[i]
            dm = i
            break loop
        end of the block
    end of the block
    if i is 7
        print 0
        return to indicate successful execution
    end of the block
    ans = integer with ans = 0
    for i = 0 to N exclusive
        for j = 0 to M exclusive
            if Judge(i, j), increment ans
        end of the block
    end of the block
    print ans
    return to indicate successful execution
end of the block

[CODE]:

int SevenPows[] = {0, 7, 49, 343, 2401, 16807, 117649};
bool visited[8];
int N, M, dh, dm;
bool Judge(int h, int m) {
    fill(visited, visited + 8, false);
    for (int i = 0; i < dm; ++i) {
        if (visited[m % 7]) return false;
        visited[m % 7] = true;
        m /= 7;
    }
    for (int i = 0; i < dh; ++i) {
        if (visited[h % 7]) return false;
        visited[h % 7] = true;
        h /= 7;
    }
    return true;
}
int main() {
    int i, j;
    cin >> N >> M;
    for (i = 0; i < 7; ++i) {
        if (N <= SevenPows[i]) {
            dh = i;
            break;
        }
    }
    if (i == 7) {
        cout << 0 << endl;
        return 0;
    }
    for (i = 0; i < 7; ++i) {
        if (M <= SevenPows[i]) {
            dm = i;
            break;
        }
    }
    if (i == 7) {
        cout << 0 << endl;
        return 0;
    }
    int ans = 0;
    for (i = 0; i < N; ++i) {
        for (j = 0; j < M; ++j) {
            if (Judge(i, j)) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}