#include <bits/stdc++.h>
using namespace std;
void CP() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  return;
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, m;
  cin >> n >> m;
  int a[n + 1];
  a[1] = 1;
  for (int i = 2; i <= n; i++) {
    a[i] = a[i - 1] + i;
  }
  for (int i = 1; i <= n; i++) {
    cerr << a[i] << " ";
  }
  cerr << endl;
  if (m == 1) {
    m -= 1;
  } else {
    if (m > a[n]) {
      m %= a[n];
      cerr << m << endl;
    }
    int i;
    for (i = n - 1; i > 1; i--) {
      if (m >= a[i]) {
        m %= a[i];
        break;
      }
    }
    if (i == 1 && m != 0) {
      m -= 1;
    }
  }
  cout << m << endl;
  return 0;
}
