Problem: Once upon a time an old man and his wife lived by the great blue sea. One day the old man went fishing and caught a real live gold fish. The fish said: "Oh ye, old fisherman! Pray set me free to the ocean and I will grant you with n gifts, any gifts you wish!". Then the fish gave the old man a list of gifts and their prices. Some gifts on the list can have the same names but distinct prices. However, there can't be two gifts with the same names and the same prices. Also, there can be gifts with distinct names and the same prices. The old man can ask for n names of items from the list. If the fish's list has p occurrences of the given name, then the old man can't ask for this name of item more than p times.

The old man knows that if he asks for s gifts of the same name, the fish will randomly (i.e. uniformly amongst all possible choices) choose s gifts of distinct prices with such name from the list. The old man wants to please his greedy wife, so he will choose the n names in such a way that he can get n gifts with the maximum price. Besides, he isn't the brightest of fishermen, so if there are several such ways, he chooses one of them uniformly.

The old man wondered, what is the probability that he can get n most expensive gifts. As the old man isn't good at probability theory, he asks you to help him.

Input

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 1000) — the number of the old man's wishes and the number of distinct names in the goldfish's list, correspondingly. Then m lines follow: the i-th line first contains integer ki (ki > 0) — the number of distinct prices of gifts with the i-th name, then ki distinct space-separated integers cij (1 ≤ cij ≤ 109), the gifts' prices. 

It is guaranteed that the sum of all ki doesn't exceed 1000. It is guaranteed that n is not greater than the total number of the gifts.

Output

On a single line print one real number — the probability of getting n most valuable gifts. The answer will be considered correct if its absolute or relative error does not exceed 10 - 9.

Examples

Input

3 1
3 10 20 30


Output

1.000000000


Input

3 2
1 40
4 10 20 30 40


Output

0.166666667

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int MAXTOT = 1010;
const int MAXN = 1010;
double p[MAXTOT][MAXN];
double ways[MAXTOT][MAXN];
int n, tot;
double cv[MAXN];
double C[MAXN][MAXN];
pair<double, int> all[MAXN];
int allcnt;
int whole[MAXTOT];
int must[MAXTOT];
int but[MAXTOT];
int main() {
  for (int i = 0; i < MAXN; ++i) C[i][0] = C[i][i] = 1.0;
  for (int i = 0; i < MAXN; ++i)
    for (int j = 1; j < i; ++j) C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
  scanf("%d%d", &n, &tot);
  allcnt = 0;
  for (int i = 1; i <= tot; ++i) {
    int ck;
    scanf("%d", &ck);
    whole[i] = ck;
    for (int j = 1; j <= ck; ++j) {
      scanf("%lf", &cv[j]);
      all[++allcnt] = make_pair(cv[j], i);
    }
  }
  sort(all + 1, all + allcnt + 1);
  int le = allcnt - n + 1, ri = le, mid = le;
  while (le > 1 && all[le - 1].first == all[le].first) --le;
  while (ri < allcnt && all[ri + 1].first == all[ri].first) ++ri;
  memset(must, 0, sizeof(must));
  for (int i = ri + 1; i <= allcnt; ++i) must[all[i].second]++;
  memset(but, 0, sizeof(but));
  for (int i = le; i <= ri; ++i) but[all[i].second]++;
  int want = ri - mid + 1;
  memset(p, 0, sizeof(p));
  p[0][0] = 1.0;
  memset(ways, 0, sizeof(ways));
  ways[0][0] = 1.0;
  for (int i = 1; i <= tot; ++i) {
    for (int j = 0; j <= want; ++j)
      for (int k = 0; k <= but[i]; ++k) ways[i][j + k] += ways[i - 1][j];
    for (int j = 0; j <= want; ++j)
      if (p[i - 1][j] > 1E-9) {
        for (int k = 0; k <= but[i]; ++k) {
          double p0 = ways[i - 1][j] / ways[i][j + k];
          double p1 = 1.0 / C[whole[i]][must[i] + k];
          p[i][j + k] += p[i - 1][j] * p0 * p1;
        }
      }
  }
  printf("%.10lf\n", p[tot][want]);
  return 0;
}