"Chef and Digits" Java solution
Naming Conventions
Variables in java should be camelCase, meaning they should start with a small letter.

Meaningful names
Someone reading your code doesn't stand a chance in hell to understand what you are trying to do without actually running this code in his head...
Your class is called Main, your only method is main... at least try to tell your reader some story on what you are trying to do, especially when you post it for review!
Variable names like n, m, num, and sum add nothing to explain your code. Names like s and S are even worse.

Efficiency
It is very hard to give efficiency advice, if I can't say what exactly you are trying to achieve, but some obvious observations:

int S[] = new int[100000];


This doesn't look very efficient - you allocate all this memory up front, and I couldn't really see where you are using it...

Your is also not very defensive - you don't close your stream in case of an exception (you should use try(PrintWriter out = new PrintWriter(System.out)) block to make sure of that), and you never validate that num[r - 1] is valid, so there is a decent chance that your code will not run as expected.

Idioms
You should use the idioms relevant for the language you use, for example - sum1 += diff; instead of sum1 = sum1 + diff;
Another example - don't wrap System.out with PrintWriter simply use System.out.println(sum2 - sum1)