#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
  int n, s;
  while(cin >> n >> s, n, s){
    int cnt = 0;
    for(int i = 0; i <= 7; i++){
      for(int j = i + 1; j <= 8; j++){
        for(int k = j + 1; k <= 9; k++){
          if(i + j + k == s){
            cnt++;
          }
        }
      }
    }
    cout << cnt << endl;
  }
}