#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  cin >> str;
  int f = 0, a = 0, p = 0;
  f = str.size();
  int flag = 0;
  int cx = 0;
  cx = f - 1;
  for (int i = 0; i < str.size(); i++) {
    if (f > 1) {
      if (str[i] >= 'A' && str[i] <= 'Z') {
        a += 1;
        flag = 1;
      } else if (str[0] >= 'a' && str[0] <= 'z' && str[i + 1] >= 'A' &&
                 str[i + 1] <= 'Z') {
        for (int i = 1; i < str.size(); i++) {
          if (str[i] >= 'A' && str[i] <= 'Z') {
            p += 1;
            flag = 2;
          }
        }
      }
    }
  }
  for (int i = 0; i < str.size(); i++) {
    if (f == 5 && str[0] >= 'a' && str[0] <= 'z' && str[1] >= 'A' &&
        str[1] <= 'Z' && str[2] >= 'a' && str[2] <= 'z' && str[3] >= 'A' &&
        str[3] <= 'Z' && str[4] >= 'a' && str[4] <= 'z') {
      cout << str[i];
    } else if (a != f && p != cx && f != 1) {
      cout << str[i];
    } else if (f == 1) {
      if (str[0] >= 'a' && str[0] <= 'z') {
        str[i] -= 32;
        cout << str[i];
      } else if (str[0] >= 'A' && str[0] <= 'Z') {
        str[i] += 32;
        cout << str[i];
      }
    } else if (a == f) {
      str[i] += 32;
      cout << str[i];
    } else if (p = f - 1) {
      str[0] -= 32;
      str[i + 1] += 32;
      cout << str[i];
    }
  }
}
