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