#include <bits/stdc++.h>
bool isUpperCase(char c) { return ((c >= 'A') && (c <= 'Z')); }
char toLowerCase(char c) {
  if ((c >= 'A') && (c <= 'Z')) {
    return c + ('a' - 'A');
  }
  return c;
}
char toUpperCase(char c) {
  if ((c >= 'a') && (c <= 'z')) {
    return c - ('a' - 'A');
  }
  return c;
}
int main(int argc, char **argv) {
  std::string word;
  std::cin >> word;
  std::string newWord = "";
  if (isUpperCase(word[0])) {
    if (word.length() == 1) {
      newWord += toLowerCase(word[0]);
    } else {
      for (unsigned int i = 1; i != word.length(); ++i) {
        if (!isUpperCase(word[i])) {
          newWord = word;
          break;
        }
      }
      if (newWord.empty()) {
        newWord += toLowerCase(word[0]);
        for (unsigned int i = 1; i != word.length(); ++i) {
          newWord += toLowerCase(word[i]);
        }
      }
    }
  } else {
    if (word.length() == 1) {
      newWord += toUpperCase(word[0]);
    } else {
      for (unsigned int i = 1; i != word.length(); ++i) {
        if (!isUpperCase(word[i])) {
          newWord = word;
          break;
        }
      }
      if (newWord.empty()) {
        newWord += toUpperCase(word[0]);
        for (unsigned int i = 1; i != word.length(); ++i) {
          newWord += toLowerCase(word[i]);
        }
      }
    }
  }
  std::cout << newWord;
  return 0;
}
