#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, i = 0;
  cin >> n >> m;
  while (m > i) {
    m -= i + 1;
    i = (i + 1) % n;
  }
  cout << m << "\n";
  return 0;
}
