#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int sum;
  sum = n * (n + 1) / 2;
  if (sum > m) {
    int c = 0, i, ans = 0;
    for (i = 1; i <= n; i++) {
      c = c + i;
      if (c <= m)
        ans = ans + i;
      else
        break;
    }
    cout << m - ans;
  } else {
    int x = m / sum;
    sum = sum * x;
    x = m - sum;
    int i, c = 0, ans = 0;
    for (i = 1; i <= n; i++) {
      c = c + i;
      if (c <= x)
        ans += i;
      else
        break;
    }
    cout << x - ans;
  }
}
