```
public class Solution {
public int addDigits(int num) {
if (num < 10) {
return num;
}
int total = 0;
while (num > 0) {
total += num % 10;
num /= 10;
if (num == 0) {
if (total < 10) {
return total;
}
num = total;
total = 0;
}
}
return -1;
}
```

}