#include <bits/stdc++.h>
using namespace std;
int CheckCaps(string str) {
  int l = str.length();
  string temp(l, ' ');
  int i = 0;
  while (i < l) {
    temp[i] = toupper(str[i]);
    i++;
  }
  if (str.compare(temp) == 0)
    return 1;
  else
    return 0;
}
int CheckFirstCaps(string str) {
  int l = str.length();
  string temp(l, ' ');
  temp[0] = toupper(str[0]);
  int i = 1;
  while (i < l) {
    temp[i] = tolower(str[i]);
    i++;
  }
  if (str.compare(temp) == 0)
    return 1;
  else
    return 0;
}
int CheckFirstSmall(string str) {
  int l = str.length();
  string temp(l, ' ');
  temp[0] = tolower(str[0]);
  int i = 1;
  while (i < l) {
    temp[i] = toupper(str[i]);
    i++;
  }
  if (str.compare(temp) == 0)
    return 1;
  else
    return 0;
}
int main() {
  string temp;
  cin >> temp;
  if (CheckCaps(temp)) {
    int l = temp.length();
    string str(l, ' ');
    int i = 0;
    while (i < l) {
      str[i] = tolower(temp[i]);
      i++;
    }
    cout << str;
  } else if (CheckFirstCaps(temp))
    cout << temp;
  else if (CheckFirstSmall(temp)) {
    int l = temp.length();
    string str(l, ' ');
    str[0] = toupper(temp[0]);
    int i = 1;
    while (i < l) {
      str[i] = tolower(temp[i]);
      i++;
    }
    cout << str;
  } else {
    cout << temp;
  }
}
