#include <bits/stdc++.h>
using namespace std;

#define ll long long
const int mod = 1e9 + 7;
#define ff first
#define ss second
#define pb push_back
#define all(v) v.begin(), v.end()
const ll inf = 2e18;

struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

int add(int a, int b) {
  int res = (a + b) % mod;
  if (res < 0)
    res += mod;
  return res;
}

int mult(int a, int b) {
  int res = (a * 1LL * b) % mod;
  if (res < mod)
    res += mod;
  return res;
}

int power(int a, int b) {
  int res = 1;
  while (b) {
    if ((b % 2) == 1)
      res = mult(res, a);
    a = mult(a, a);
    b /= 2;
  }
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string &s) { return '"' + s + '"'; }
string to_string(const char *s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
string to_string(char c) { return to_string(string(1, c)); }

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N> string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A> string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B> string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " +
         to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void dbg() { cout << endl; }
template <typename Head, typename... Tail> void dbg(Head H, Tail... T) {
  cout << " " << to_string(H);
  dbg(T...);
}

#ifdef LOCAL
#define debug(...) cout << "[" << #__VA_ARGS__ << "]:", dbg(__VA_ARGS__)
#else
#define debug(...)
#endif

void solve() {
  ll n;
  cin >> n;
  if (n <= 2) {
    cout << "1\n";
    return;
  }
  ll low = 1;
  ll high = 2e9 + 2;
  ll ans;
  while (low <= high) {
    ll mid = (low + high) / 2;
    if (mid * (mid + 1) <= 2 * (n + 1)) {
      ans = mid;
      low = mid + 1;
    } else {
      high = mid - 1;
    }
  }
  cout << (n - ans + 1) << "\n";
}

int32_t main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed << setprecision(10);

  int t = 1;
  // cin >> t;

  for (int i = 1; i <= t; i++) {
    // cout<<"Case "<<i<<": ";
    solve();
  }
}
#include <stdio.h>
#include <iostream>
#include <cmath>
#include <vector>
#include <numeric>
#include <string>

int main() {
	int k;
	std::cin >> k;
	std::vector<int> v(10, k);
	std::vector<double> tv(10, 0);
	std::vector<double> av(10, 0);
	int ta = 0; 
	int ao = 0;
	std::string s;

	std::cin >> s;

	for (int c = 0; c < 4; c++) {
		int f;
		f = std::stoi(s.substr(c, 1));
		tv[f] += 1;
		v[f] -= 1;
	}

	
	for (int c = 1; c < 10; c++) {
		ta += c*pow(10, tv[c]);
	}

	std::cin >> s;

	for (int c = 0; c < 4; c++) {
		int f;
		f = std::stoi(s.substr(c, 1));
		av[f] += 1;
		v[f] -= 1;
	}

	for (int c = 1; c < 10; c++) {
		ao += c*pow(10, av[c]);
	}


	double ans = 0.;

	for (int c = 1; c < 10; c++) {
		for (int b = 1; b < 10; b++) {
			if (c == b) {
				if (v[c] > 1) {
					if (ao + b * pow(10, av[b] + 1) - b * pow(10, av[b]) < ta + c * pow(10, tv[c] + 1) - c * pow(10, tv[c])) {
						ans += static_cast<double>(v[c]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0)) * static_cast<double>(v[c] - 1) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0) - 1);
					}
				}
			}
			else {
				if (v[c] > 0 && v[b] > 0) {
					if (ao + b * pow(10, av[b] + 1) - b * pow(10, av[b]) < ta + c * pow(10, tv[c] + 1) - c * pow(10, tv[c])) {
						ans += static_cast<double>(v[c]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0)) * static_cast<double>(v[b]) / static_cast<double>(std::accumulate(v.begin() + 1, v.end(), 0) - 1);
					}
				}
			}
		}
	}

	std::cout << ans << std::endl;

}