#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
void print_array(int arr[], int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << ' ';
  cout << endl;
}
void print_vector(const vector<int> &a) {
  for (int i = 0; i < (int)a.size(); i++) cout << a[i] << ' ';
}
int main() {
  int n, m;
  cin >> n >> m;
  int sum = n * (n + 1) / 2;
  while (m > sum) {
    m = m - sum;
  }
  for (int i = 1; i <= n; i++) {
    if (m - i < 0) break;
    m = m - i;
  }
  cout << m << endl;
}
