#include <iostream>
using namespace std;

int main() {
    int num;
    cin >> num;

    // 提取原数的各位数字
    int thousands = num / 1000;
    int hundreds = (num / 100) % 10;
    int tens = (num / 10) % 10;
    int units = num % 10;

    // 合成倒序的新数
    int reversedNum = units * 1000 + tens * 100 + hundreds * 10 + thousands;

    // 计算差值
    int difference = num - reversedNum;

    cout << difference << endl;

    return 0;
}    
/**************************************************************
	Problem: 1702
	User: fuyijun
	Language: C++
	Result: Accepted
	Time:7 ms
	Memory:2072 kb
****************************************************************/