#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}
template<typename T>vector<T> & cset(vector<T> &A,T e=T()){for(auto &I:A){I=e;} return A;}


#ifndef SEGMENT_TREE
#define SEGMENT_TREE

template<typename Data,typename Mono>
class SegTree{
private:
  typedef function<void(Data&,Data&)> MergeData;
  typedef function<void(Mono&,Mono&)> MergeMono;
  typedef function<void(Data&,Mono&)> Culc;
  typedef function<bool(Data&,Mono&,int&,int&)> UpdateQuery; //data,mono,left,right true::Data,Monoに作用する false::子に降りる


  int size,high;
  vector<int> left,right;
  vector<Data> dv;
  vector<Mono> mv;
  
  Data de;
  Mono me;
  MergeData df;
  MergeMono mf;
  Culc cf;
  

  inline bool nx(int &idx){
    while(idx&1){idx>>=1; if(idx){reculc(idx);}}
    return idx?idx|=1:idx;
  }

  inline void reculc(int idx){
    dv[idx]=dv[idx<<1];
    df(dv[idx],dv[(idx<<1)|1]);
    cf(dv[idx],mv[idx]);
  }

  inline void down(int idx){
    cf(dv[idx<<1],mv[idx]);
    mf(mv[idx<<1],mv[idx]);
    cf(dv[(idx<<1)|1],mv[idx]);
    mf(mv[(idx<<1)|1],mv[idx]);
    mv[idx]=me;
  }

public:
  SegTree(Data de,Mono me,MergeData df,MergeMono mf,Culc cf,int n=0):de(de),me(me),df(df),mf(mf),cf(cf){init(n);}

  void init(int n){
    size=1;
    high=0;
    while(size<n){size<<=1; high++;}
    dv.assign(size<<1,de);
    mv.assign(size<<1,me);
    left.resize(size<<1);
    right.resize(size<<1);
    for(int i=0;i<size;i++){left[size|i]=i; right[size|i]=i+1;}
    for(int i=size-1;i>0;i--){left[i]=left[i<<1]; right[i]=right[(i<<1)|1];}
  }

  void build(const vector<Data> &ary){
    int n=ary.size();
    init(n);
    for(int i=0;i<n;i++){dv[size|i]=ary[i];}
    for(int i=size-1;i>0;i--){dv[i]=dv[i<<1]; df(dv[i],dv[(i<<1)|1]);}
  }

  //[lf,rg)
  Data query(int lf,int rg){
    Data ret=de;
    int idx=1;
    bool j=true;
    while(j){
      if(right[idx]<=lf || rg<=left[idx]){j&=nx(idx);}
      else if(lf<=left[idx] && right[idx]<=rg){df(ret,dv[idx]); j&=nx(idx);}
      else{down(idx); idx<<=1;}
    }
    return ret;
  }

  void update(int lf,int rg,Mono m){
    int idx=1;
    bool j=true;
    while(j){
      if(right[idx]<=lf || rg<=left[idx]){j&=nx(idx);}
      else if(lf<=left[idx] && right[idx]<=rg){
        cf(dv[idx],m); mf(mv[idx],m); j&=nx(idx);
      }
      else{down(idx); idx<<=1;}
    }
  }

  void update(int lf,int rg,UpdateQuery br){
    int idx=1;
    bool j=true;
    while(j){
      if(right[idx]<=lf || rg<=left[idx]){j&=nx(idx);}
      else if(lf<=left[idx] && right[idx]<=rg){
        if(br(dv[idx],mv[idx],left[idx],right[idx])){j&=nx(idx);}
        else{down(idx); idx<<=1;}
      }
      else{down(idx); idx<<=1;}
    }
  }

  void DEBUG(){cout<<dv<<endl;}
};

#endif /*SEGMENT_TREE*/


void DSL_2_A(){
  ll n,q;
  cin>>n>>q;
  auto df=[](ll &a,ll &b)->void{a=min(a,b);};
  auto mf=[](pll &a,pll &b)->void{a=(b.F==0?a:b);};
  auto cf=[](ll &a,pll &b)->void{if(b.F!=0){a=b.S;}};
  ll de=1e18;
  pll me={0,0};
  SegTree<ll,pll> Tr(de,me,df,mf,cf);
  Tr.build(vector<ll>(n,(1LL<<31)-1));
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c){
      cout<<Tr.query(x,y+1)<<endl;
    }
    else{
      Tr.update(x,x+1,{1,y});
    }
  }
}

void DSL_2_B(){
  ll n,q;
  cin>>n>>q;
  auto df=[](ll &a,ll &b)->void{a+=b;};
  auto mf=[](ll &a,ll &b)->void{a+=b;};
  auto cf=[](ll &a,ll &b)->void{a+=b;};
  ll de=0;
  ll me=0;
  SegTree<ll,ll> Tr(de,me,df,mf,cf);
  Tr.build(vector<ll>(n,0));
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c){
      x--;
      cout<<Tr.query(x,y)<<endl;
    }
    else{
      x--;
      Tr.update(x,x+1,y);
    }
  }
}

void DSL_2_D(){
  ll n,q;
  cin>>n>>q;
  auto df=[](ll &a,ll &b)->void{a=min(a,b);};
  auto mf=[](pll &a,pll &b)->void{a=(b.F==0?a:b);};
  auto cf=[](ll &a,pll &b)->void{if(b.F!=0){a=b.S;}};
  ll de=1e18;
  pll me={0,0};
  SegTree<ll,pll> Tr(de,me,df,mf,cf);
  Tr.build(vector<ll>(n,(1LL<<31)-1));
  for(int i=0;i<q;i++){
    int c,x,y,z;
    cin>>c;
    if(c){
      cin>>x;
      cout<<Tr.query(x,x+1)<<endl;
    }
    else{
      cin>>x>>y>>z;
      Tr.update(x,y+1,{1,z});
    }
  }
}

void DSL_2_E(){
  ll n,q;
  cin>>n>>q;
  auto df=[](pll &a,pll &b)->void{a.F+=b.F; a.S+=b.S;};
  auto mf=[](ll &a,ll &b)->void{a+=b;};
  auto cf=[](pll &a,ll &b)->void{a.F+=b*a.S;};
  pll de={0,0};
  ll me=0;
  SegTree<pll,ll> Tr(de,me,df,mf,cf);
  Tr.build(vector<pll>(n,{0,1}));
  for(int i=0;i<q;i++){
    int c,x,y,z;
    cin>>c>>x;
    x--;
    if(c){
      cout<<Tr.query(x,x+1).F<<endl;
    }
    else{
      cin>>y>>z;
      Tr.update(x,y,z);
    }
  }
}

void DSL_2_F(){
  ll n,q;
  cin>>n>>q;
  auto df=[](ll &a,ll &b)->void{a=min(a,b);};
  auto mf=[](pll &a,pll &b)->void{a=(b.F==0?a:b);};
  auto cf=[](ll &a,pll &b)->void{if(b.F!=0){a=b.S;}};
  ll de=1e18;
  pll me={0,0};
  SegTree<ll,pll> Tr(de,me,df,mf,cf);
  Tr.build(vector<ll>(n,(1LL<<31)-1));
  for(int i=0;i<q;i++){
    int c,x,y,z;
    cin>>c;
    if(c){
      cin>>x>>y;
      cout<<Tr.query(x,y+1)<<endl;
    }
    else{
      cin>>x>>y>>z;
      Tr.update(x,y+1,{1,z});
    }
  }
}

void DSL_2_G(){
  ll n,q;
  cin>>n>>q;
  auto df=[](pll &a,pll &b)->void{a.F+=b.F; a.S+=b.S;};
  auto mf=[](ll &a,ll &b)->void{a+=b;};
  auto cf=[](pll &a,ll &b)->void{a.F+=b*a.S;};
  pll de={0,0};
  ll me=0;
  SegTree<pll,ll> Tr(de,me,df,mf,cf);
  Tr.build(vector<pll>(n,{0,1}));
  for(int i=0;i<q;i++){
    int c,x,y,z;
    cin>>c>>x;
    x--;
    if(c){
      cin>>y;
      cout<<Tr.query(x,y).F<<endl;
    }
    else{
      cin>>y>>z;
      Tr.update(x,y,z);
    }
  }
}

void DSL_2_H(){
  ll n,q;
  cin>>n>>q;
  auto df=[](ll &a,ll &b)->void{a=min(a,b);};
  auto mf=[](ll &a,ll &b)->void{a+=b;};
  auto cf=[](ll &a,ll &b)->void{a+=b;};
  ll de=1e18;
  ll me=0;
  SegTree<ll,ll> Tr(de,me,df,mf,cf);
  Tr.build(vector<ll>(n,0));
  for(int i=0;i<q;i++){
    int c,x,y,z;
    cin>>c>>x;
    if(c){
      cin>>y;
      cout<<Tr.query(x,y+1)<<endl;
    }
    else{
      cin>>y>>z;
      Tr.update(x,y+1,z);
    }
  }
}

void DSL_2_I(){
  ll n,q;
  cin>>n>>q;
  auto df=[](pll &a,pll &b)->void{a.F+=b.F; a.S+=b.S;};
  auto mf=[](pll &a,pll &b)->void{a=(b.F==0?a:b);};
  auto cf=[](pll &a,pll &b)->void{if(b.F){a.F=b.S*a.S;}};
  pll de={0,0};
  pll me={0,0};
  SegTree<pll,pll> Tr(de,me,df,mf,cf);
  Tr.build(vector<pll>(n,{0,1}));
  for(int i=0;i<q;i++){
    int c,x,y,z;
    cin>>c>>x;
    if(c){
      cin>>y;
      cout<<Tr.query(x,y+1).F<<endl;
    }
    else{
      cin>>y>>z;
      Tr.update(x,y+1,{1,z});
    }
  }
}

int main(){
  DSL_2_H();

  return 0;
}



Measured memory_bytes: 9772