#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  int i, n;
  cin >> s;
  bool change1 = false, change2 = false, unchange = false;
  if (s.size() < 2) {
    if (s[0] >= 65 && s[0] <= 90) {
      s[0] += 32;
      cout << s << endl;
    } else {
      s[0] -= 32;
      cout << s << endl;
    }
  } else if (s[0] >= 65 && s[0] <= 90) {
    for (i = 1; i < s.size(); i++) {
      if (s[i] >= 97 && s[i] <= 122) {
        change1 = false;
        unchange = true;
        break;
      } else {
        change1 = true;
      }
    }
  } else {
    for (i = 1; i < s.size(); i++) {
      if (s[i] >= 97 && s[i] <= 122) {
        change2 = false;
        unchange = true;
        break;
      } else {
        change2 = true;
      }
    }
  }
  if (change1) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    cout << s << endl;
  } else if (change2) {
    transform(s.begin(), s.end(), s.begin(), ::tolower);
    s[0] -= 32;
    cout << s << endl;
  } else if (unchange) {
    cout << s << endl;
  }
  return 0;
}
