#include <bits/stdc++.h>
bool isvowel(char s) {
  if (s == 'a' || s == 'A' || s == 'e' || s == 'E' || s == 'i' || s == 'I' ||
      s == 'o' || s == 'O' || s == 'u' || s == 'U')
    return true;
  else
    return false;
}
long long fact(long long n) {
  long long mul = 1;
  for (long long i = 1; i <= n; i++) mul = mul * i;
  return mul;
}
long long gcd(long long m, long long n) {
  while (n != 0) {
    long long r = m % n;
    m = n;
    n = r;
  }
  return m;
}
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    m -= i;
    if (m == 0) {
      cout << m;
      return 0;
    }
    if (m < 0) {
      m = m + i;
      cout << m;
      return 0;
    }
    if (i == n) i = 0;
  }
  return 0;
}
