1. Abridged Problem Statement
Given two integers N (day) and M (month) for a date in the year 2001, output the weekday number (Monday=1, …, Sunday=7). If the date is invalid (e.g., month not in 1–12 or day exceeds that month's length in 2001), print "Impossible".

2. Detailed Editorial
We know that January 1, 2001, was a Monday. To find the weekday of any date N M in 2001:
  • First, validate M is in [1..12] and N is in [1..days_in_month[M]]. If not, answer is "Impossible."
  • Otherwise, compute the total number of days elapsed from January 1 to the given date, call it D (0 for Jan 1, 1 for Jan 2, …).
    – Let days_in_month = [31,28,31,30,31,30,31,31,30,31,30,31].
    – Set D = (sum of days in months 1 through M–1) + (N–1).
  • The weekday index is then (D mod 7) + 1, since D=0 → Monday=1, …, D=6 → Sunday=7, then it repeats.
This runs in O(1) time and constant space.

3. C++ Solution

```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;
}
```

4. Python Solution with Detailed Comments
```python
import sys

def main():
    data = sys.stdin.read().split()
    if len(data) < 2:
        return
    n, m = map(int, data)       # n = day, m = month

    # Month lengths in 2001 (non-leap year)
    months = [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 > months[m - 1]:
        print("Impossible")
        return

    # Compute days elapsed since Jan 1 (zero-based)
    days_elapsed = sum(months[:m - 1]) + (n - 1)

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

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

5. Compressed Editorial
Compute D = sum of days in months before M plus (N–1). If M∉[1..12] or N>month_length[M], print "Impossible". Else output (D mod 7)+1, since Jan 1, 2001 is Monday (D=0→1).
