#include <bits/stdc++.h>
using namespace std;
int main() {
  string s;
  cin >> s;
  int small = 0;
  int cap = 0;
  for (int i = 0; i < s.length(); i++) {
    if (s[i] < 97) cap++;
  }
  if (cap == s.length()) {
    for (int i = 0; i < s.length(); i++) {
      char a = s[i] + 32;
      cout << a;
    }
  } else if (s[0] >= 97 && cap == s.length() - 1) {
    for (int i = 0; i < s.length(); i++) {
      char a;
      if (s[i] > 96)
        a = s[i] - 32;
      else
        a = s[i] + 32;
      cout << a;
    }
  } else
    cout << s << endl;
}
