#include <bits/stdc++.h>
using namespace std;
struct info {
  int l, r, x = 0;
};
bool intersects(int l, int r, int tl, int tr) {
  return max(tl, l) <= min(r, tr);
}
void solve() {
  int n, m;
  cin >> n >> m;
  int i = 1;
  while (m >= i) {
    m -= i;
    i++;
    if (i == n + 1) {
      i = 1;
    }
  }
  cout << m;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
