#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int d = (n * (n + 1)) / 2;
  m = m % d;
  for (int i = 1; i <= n; i++) {
    if (m - i == 0) {
      cout << "0\n";
      return 0;
    } else if (m - i < 0) {
      cout << m << "\n";
      return 0;
    } else
      m = m - i;
  }
}
