#import <Foundation/Foundation.h>
int main(){
    @autoreleasepool {
        char c;
        NSMutableArray *A = [NSMutableArray array];
        NSMutableArray *B = [NSMutableArray array];
        NSMutableArray *X = [NSMutableArray array];
        NSMutableArray *Y = [NSMutableArray array];
        int xs = 0;
        while((c=getchar())!=EOF){
            if (!(c>='a'&&c<='z')) break;
            if (c=='x') {
                xs++;
            } else {
                [X addObject:@(xs)];
                [Y insertObject:@(xs) atIndex:0];
                xs = 0;
                [A addObject:@(c)];
                [B insertObject:@(c) atIndex:0];
            }
        }
        [X addObject:@(xs)];
        [Y insertObject:@(xs) atIndex:0];
        if ([A isEqualToArray:B]) {
            long s = 0;
            for(long i=0;i<[X count]/2;i++){
                s += ABS([[X objectAtIndex:i] integerValue] - [[Y objectAtIndex:i] integerValue]);
            }
            printf("%ld",s);
        } else {
            puts("-1");
        }
    }
}
