#include <bits/stdc++.h>
using namespace std;
int n,m,a[30],b[30],c[50005],d[50005],maxi,br,polj,dp[50005];
int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>a[i]>>b[i];
  }
  for(int i=1;i<=m;i++){
    cin>>c[i]>>d[i];
    maxi+=d[i];
    if(d[i]>0){
      br++;
      dp[br]=i;
    }
  }
  br=min(b[1],br);
  maxi=min(maxi,b[1]);
  cout<<maxi<<endl;
  cout<<br<<endl;
  for(int i=1;i<=br;i++){
    cout<<1<<" "<<dp[br]<<d[dp[br]]<<endl;
  }
  return 0;
}