#include <bits/stdc++.h>
using namespace std;
long long powermodm(long long x, long long n, long long M) {
  long long result = 1;
  while (n > 0) {
    if (n % 2 == 1) result = (result * x) % M;
    x = (x * x) % M;
    n = n / 2;
  }
  return result;
}
long long modInv(long long x, long long M) { return powermodm(x, M - 2, M); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  bool firstOn;
  if (s[0] >= 'A' && s[0] <= 'Z') {
    firstOn = true;
  } else {
    firstOn = false;
  }
  long long caps = 0;
  for (long long i = 1; i < s.length(); i++) {
    if (s[i] >= 'A' && s[i] <= 'Z') {
      caps++;
    }
  }
  if (caps == s.length() - 1) {
    for (long long i = 0; i < s.length(); i++) {
      if (s[i] >= 'A' && s[i] <= 'Z') {
        cout << ((char)(s[i] + 32));
      } else {
        cout << ((char)(s[i] - 32));
      }
    }
  } else {
    cout << s;
  }
  cout << '\n';
  return 0;
}
