#include <bits/stdc++.h>
using namespace std;
int main() {
  string word, corrected_word = "";
  cin >> word;
  int uppercase_count = 0, word_length = word.length();
  bool starts_with_lower = false;
  if (isupper(word[0])) {
    ++uppercase_count;
    corrected_word += tolower(word[0]);
  } else {
    starts_with_lower = true;
    corrected_word += toupper(word[0]);
  }
  for (int i = 1; i < word_length; ++i) {
    if (isupper(word[i])) {
      ++uppercase_count;
      corrected_word += tolower(word[i]);
    } else
      corrected_word += toupper(word[i]);
  }
  if (uppercase_count == word_length ||
      (uppercase_count == word_length - 1 && starts_with_lower))
    cout << corrected_word;
  else
    cout << word;
  return 0;
}
