ADIGIT wrong answer

plzzzz tell me what’s wrong with this code(april challenge…ADIGIT)

#include<stdio.h>
//#include<conio.h>
#include<stdlib.h>
int main()
{
    long long int n1,m,x,sum,j;
    scanf("%lld%lld",&n1,&m);
    int a[n1+1];
    char digits[n1+1],ch;
    int i;
    for(i=0;i<=n1+1;i++)
    {
        ch=getchar();
        digits[i]=ch;
    }
    
    a[0]=0;
    for(i=1;i<=n1+1;i++)
    a[i]=digits[i]-48;
  while(m--)
    {
         j=1;
        sum=0;
        scanf("%lld",&x);
        while(x!=j)
        {
         if(a[x]<a[j])
         {
         sum=sum-a[x]+a[j];
         j=j+1;
         }
         else
         {
        sum=sum+(a[x]-a[j]);
        j=j+1;
         }
        }
        printf("%lld\n",sum);
    }

//	getch();
	return 0;
}