#include <bits/stdc++.h>
using namespace std;
bool uppy(string &s) {
  if (s.length() > 1)
    for (int i = 1; i < (int)s.length(); i++)
      if (islower(s[i])) return false;
  return true;
}
void up(char &ch) {
  if (islower(ch)) ch -= 32;
}
void low(char &ch) {
  if (isupper(ch)) ch += 32;
}
void trans(string &s) {
  if (uppy(s)) {
    for (int i = 0; i < (int)s.length(); i++)
      if (islower(s[i]))
        up(s[i]);
      else
        low(s[i]);
  }
  cout << s;
}
int main() {
  string s;
  cin >> s;
  trans(s);
  return 0;
}
