program atgc3
  implicit none
  character(len=100000) :: S
  integer :: i,j,N,Q,CountAC,sita,ue
  integer,allocatable :: LR(:,:)
  integer,allocatable :: Flags(:)
  read(*,*) N,Q
  allocate(LR(2,Q))
  read(*,*) S
  !write(*,*) trim(S)                                                                                                                                                                                                             
  allocate(Flags(N))
  Flags=0

  !write(*,*) Flags                                                                                                                                                                                                               
  sita=N
  ue=1
  do i=1,Q
     read(*,*) LR(:,i)
     if(sita.gt.LR(1,i)) then
        sita=LR(1,i)
     endif
     if(ue.lt.LR(2,i)) then
        ue=LR(2,i)
     endif
  enddo
  do i=sita,ue
     if(S(i:i+1).eq.'AC') then
        Flags(i)=1
     endif
  enddo

  do i=1,Q
     CountAC=sum(Flags(LR(1,i):LR(2,i)-1))
     write(*,'(i0)') CountAC
  enddo

  deallocate(LR)
  deallocate(Flags)


end program atgc3