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