<|instruction|>
Solve the below problem. The solution should start with an abridged problem statement. Then key observations. Then full solution based on the observations. Then C++ and Python implementations with comments.

115. Calendar

time limit per test: 0.25 sec.
memory limit per test: 4096 KB


First year of new millenium is gone away. In commemoration of it write a program that finds the name of the day of the week for any date in 2001.


Input

Input is a line with two positive integer numbers N and M, where N is a day number in month M. N and M is not more than 100.


Output

Write current number of the day of the week for given date (Monday – number 1, … , Sunday – number 7) or phrase “Impossible” if such date does not exist.


Sample Input

21 10
Sample Output

7
Author	: Michael R. Mirzayanov
Resource	: PhTL #1 Training Contests
Date	: January 2002

<|response|>
1. Abridged Problem Statement
Given two integers N and M representing a date N-th day of month M in the year 2001, output the weekday number (Monday=1, …, Sunday=7). If the date is not valid (month not in 1…12 or day exceeds that month's length), print “Impossible”.

2. Key Observations
• 2001 is not a leap year, so month lengths are fixed:
  January=31, February=28, March=31, April=30, …, December=31.
• January 1, 2001 was a Monday.
• If you count days elapsed since Jan 1 (zero-based), day D after Jan 1 falls on weekday index ((D mod 7) + 1).
  – D=0 → Monday(1), D=1 → Tuesday(2), …, D=6 → Sunday(7), then it repeats.

3. Full Solution Approach
Step 1: Read integers N (day) and M (month).
Step 2: Validate:
  – 1 ≤ M ≤ 12
  – 1 ≤ N ≤ days_in_month[M]
  If invalid, print “Impossible” and exit.
Step 3: Compute days elapsed since Jan 1 in zero-based form:
  D = sum of lengths of months 1 to M−1  +  (N − 1)
Step 4: Compute weekday = (D mod 7) + 1
Step 5: Print weekday.

This runs in O(1) time and uses constant space.

4. C++ Implementation
```cpp
#include <bits/stdc++.h>

using namespace std;

template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& x) {
    return out << x.first << ' ' << x.second;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& x) {
    return in >> x.first >> x.second;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& a) {
    for(auto& x: a) {
        in >> x;
    }
    return in;
};

template<typename T>
ostream& operator<<(ostream& out, const vector<T>& a) {
    for(auto x: a) {
        out << x << ' ';
    }
    return out;
};

int day, month;

void read() { cin >> day >> month; }

void solve() {
    // 2001 is not a leap year and Jan 1, 2001 was a Monday. Validate the date
    // against the month lengths, then count the days elapsed since Jan 1 and
    // map that offset modulo 7 onto Monday..Sunday (1..7).

    vector<int> months = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

    if(month <= 0 || day <= 0 || month > 12 || day > months[month - 1]) {
        cout << "Impossible" << '\n';
        return;
    }

    int offset = day - 1;
    for(int i = 1; i < month; i++) {
        offset += months[i - 1];
    }

    cout << (offset % 7) + 1 << '\n';
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int T = 1;
    // cin >> T;
    for(int test = 1; test <= T; test++) {
        read();
        // cout << "Case #" << test << ": ";
        solve();
    }

    return 0;
}
```

5. Python Implementation with Detailed Comments
```python
import sys

def main():
    data = sys.stdin.read().split()
    if len(data) < 2:
        return
    N, M = map(int, data)

    # Month lengths for 2001
    monthlen = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

    # Validate input
    if M < 1 or M > 12 or N < 1 or N > monthlen[M-1]:
        print("Impossible")
        return

    # Compute days elapsed since Jan 1 in zero-based form
    days_elapsed = sum(monthlen[:M-1]) + (N - 1)

    # Compute weekday: Monday=1 … Sunday=7
    weekday = (days_elapsed % 7) + 1
    print(weekday)

if __name__ == "__main__":
    main()
```
