#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
bool sortinrev(long long x, long long y) { return x > y; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  string s;
  cin >> s;
  long long count = 0;
  for (long long i = 0; i < s.length(); i++) {
    if (s[i] >= 65 && s[i] <= 90) count++;
  }
  if (count == s.length()) {
    for (long long i = 0; i < s.length(); i++) {
      if (s[i] >= 65 && s[i] <= 90) s[i] = s[i] + 32;
    }
  } else if ((s[0] >= 97 && s[0] <= 122 && count == s.length() - 1)) {
    if (s[0] >= 97 && s[0] <= 122) s[0] = s[0] - 32;
    for (long long i = 1; i < s.length(); i++) {
      if (s[i] >= 65 && s[i] <= 90) s[i] = s[i] + 32;
    }
  }
  cout << s;
  return 0;
}
