#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  if (s[0] >= 'a' && s[0] <= 'z') {
    bool f = true;
    for (int i = 1; i < s.size(); i++) {
      if (s[i] >= 'A' && s[i] <= 'Z')
        continue;
      else {
        f = false;
        break;
      }
    }
    if (!f)
      cout << s << endl;
    else {
      for (int i = 0; i < s.size(); i++) {
        if (s[i] >= 'a' && s[i] <= 'z') {
          s[i] -= 32;
          cout << s[i];
        } else {
          s[i] += 32;
          cout << s[i];
        }
      }
      cout << endl;
    }
  } else {
    bool f = true;
    for (int i = 0; i < s.size(); i++) {
      if (s[i] > 'Z') {
        f = false;
        break;
      }
    }
    if (f) {
      for (int i = 0; i < s.size(); i++) {
        s[i] += 32;
        cout << s[i];
      }
      cout << endl;
    } else
      cout << s << endl;
  }
  return 0;
}
