#include <stdio.h>
#include <stdint.h>
union{
unsigned char reg;
struct {
uint8_t lower_nibble: 4;
uint8_t upper_nibble: 4;
}reg_t;
}reg_u;
int main() {
int pos;
scanf("%hhu %d", ®_u.reg, &pos);
if(pos){
printf("%d", reg_u.reg_t.upper_nibble);
}
else{
printf("%d", reg_u.reg_t.lower_nibble);
}
return 0;
}