z,g,w,f;main(i){for(;read(0,&z,1);)f=z&1?z%3?g++,f&1|--w<0:(w++,f|2):z&8?g=w=--i&&!puts("impossible"+!f*!g*2):f|--g<0;}