1 #include<bits/stdc++.h>
2 #define ls u<<1
3 #define rs ls|1
4 #define N 200010
5 using namespace std;
6 int n,m,a[N],b[N],pd[N<<2],lz[N<<2],lx[N<<2],rx[N<<2];char s[N];
7 void pushup(int u,int l,int r){
8 int mid=(l+r)>>1;
9 pd[u]=pd[ls]|pd[rs];
10 lx[u]=lx[ls];rx[u]=rx[rs];
11 if(lx[u]==mid-l+1)lx[u]+=lx[rs];
12 if(rx[u]==r-mid)rx[u]+=rx[ls];
13 }
14 void build(int u,int l,int r){
15 if(l==r){
16 if(!b[l])pd[u]=lx[u]=rx[u]=1;
17 else pd[u]=lx[u]=rx[u]=0;
18 return;
19 }
20 int mid=(l+r)>>1;
21 build(ls,l,mid);
22 build(rs,mid+1,r);
23 pushup(u,l,r);
24 }
25 void update(int u,int l,int r,int p){
26 if(l==r){
27 if(!b[l])pd[u]=lx[u]=rx[u]=1;
28 else pd[u]=lx[u]=rx[u]=0;
29 return;
30 }
31 int mid=(l+r)>>1;
32 if(p<=mid)update(ls,l,mid,p);
33 else update(rs,mid+1,r,p);
34 pushup(u,l,r);
35 }
36
37 int query(int u,int L,int R,int l,int r){
38 if(l<=L&&R<=r)return pd[u];
39 int mid=(L+R)>>1,ret=0;
40 if(l<=mid)ret|=query(ls,L,mid,l,r);
41 if(r>mid)ret|=query(rs,mid+1,R,l,r);
42 return ret;
43 }
44 int asklx(int u,int L,int R,int l,int r){
45 if(l==L&&R==r)return lx[u];
46 int mid=(L+R)>>1,ret=0;
47 if(r<=mid)return asklx(ls,L,mid,l,r);
48 if(l>mid)return asklx(rs,mid+1,R,l,r);
49 ret+=asklx(ls,L,mid,l,mid);
50 if(!ret)return 0;
51 if(ret==mid-l+1)ret+=asklx(rs,mid+1,R,mid+1,r);
52 return ret;
53 }
54 int askrx(int u,int L,int R,int l,int r){
55 if(l==L&&R==r)return rx[u];
56 int mid=(L+R)>>1,ret=0;
57 if(r<=mid)return askrx(ls,L,mid,l,r);
58 if(l>mid)return askrx(rs,mid+1,R,l,r);
59 ret+=askrx(rs,mid+1,R,mid+1,r);
60 if(!ret)return 0;
61 if(ret==r-mid)ret+=askrx(ls,L,mid,l,mid);
62 return ret;
63 }
64 inline int solve(int x){
65 static int t1,t2,x1,x2,L,R,l,r;
66 int mid=(1+n)>>1;
67 if(x<mid)x+=n;
68 L=x-mid+1;R=x+mid;
69 if(!((1+n)&1))R--;
70 t1=t2=0;
71 l=x,r=R;
72 while(l<=r){
73 mid=(l+r)>>1;
74 if(query(1,1,n<<1,mid,R))t2=mid,l=mid+1;
75 else r=mid-1;
76 }
77 l=L,r=x;
78 while(l<=r){
79 mid=(l+r)>>1;
80 if(query(1,1,n<<1,L,mid))t1=mid,r=mid-1;
81 else l=mid+1;
82 }
83 if(!t1&&!t2)return -1;
84 if(t1==x&&t2==x)return 0;
85 x1=t1+asklx(1,1,n<<1,t1,x)-1;
86 x2=t2-askrx(1,1,n<<1,x,t2)+1;
87 if(x1==x&&x2==x)return 0;
88 if(t1==L&&t2==R)return min(x2-x,x-x1);
89 return max(x2-x,x-x1);
90 }
91 inline void change(int p,int op){
92 static int k;k=p-1;if(!k)k=n;
93 if(op)b[p]=(a[k]+a[p])%10;
94 else b[p]=1ll*a[k]*a[p]%10;
95 if(p>n)b[p-n]=b[p];
96 else b[p+n]=b[p];
97 }
98 int main(){
99 scanf("%d%d",&n,&m);
100 for(int i=1;i<=n;i++)
101 scanf("%d %c",&a[i],&s[i]);
102 for(int i=1;i<=n;i++){
103 int j=i-1;if(!j)j=n;
104 if(s[i]=='+')b[i]=(a[i]+a[j])%10;
105 else b[i]=1ll*a[i]*a[j]%10;
106 b[i+n]=b[i];s[i+n]=s[i];a[i+n]=a[i];
107 }
108 build(1,1,n<<1);
109 int x,y,z,p;char op;
110 while(m--){
111 scanf("%d%d",&x,&y);++y;
112 if(x==1){
113 scanf("%d %c",&z,&op);
114 a[y]=a[y+n]=z;s[y]=s[y+n]=op;
115 change(y,s[y]=='+'?1:0);
116 update(1,1,n<<1,y);
117 update(1,1,n<<1,y+n);
118 change(y+1,s[y+1]=='+'?1:0);
119 update(1,1,n<<1,y+1);
120 p=y+1>n?y+1-n:y+1+n;
121 update(1,1,n<<1,p);
122 }
123 else printf("%d\n",solve(y));
124 }
125 return 0;
126 }