Let $ n $ be a positive integer. A sequence $(a_1,a_2,\ldots,a_n)$ of length is called $balanced$ if for every $ k $ $(1\leq k\leq n)$ the term $ a_k $ is equal with the number of distinct numbers from the subsequence $(a_1,a_2,\ldots,a_k).$
a) How many balanced sequences $(a_1,a_2,\ldots,a_n)$ of length $ n $ do exist?
b) For every positive integer $m$ find how many balanced sequences $(a_1,a_2,\ldots,a_n)$ of length $ n $ exist such that $a_n=m.$
To solve this problem, we need to understand the definition of a balanced sequence and use it to derive the number of such sequences of length \( n \).

### Part (a)
1. **Definition of Balanced Sequence**:
   A sequence \((a_1, a_2, \ldots, a_n)\) is called balanced if for every \( k \) \((1 \leq k \leq n)\), the term \( a_k \) is equal to the number of distinct numbers from the subsequence \((a_1, a_2, \ldots, a_k)\).

2. **Initial Condition**:
   For \( k = 1 \), \( a_1 \) must be 1 because there is only one element in the subsequence \((a_1)\), and it must be distinct.

3. **Recursive Condition**:
   For \( k > 1 \), \( a_k \) can either be:
   - \( a_{k-1} \) (if the \( k \)-th element does not introduce a new distinct number), or
   - \( a_{k-1} + 1 \) (if the \( k \)-th element introduces a new distinct number).

4. **Counting Balanced Sequences**:
   - For each position \( k \) from 2 to \( n \), there are 2 choices: either \( a_k = a_{k-1} \) or \( a_k = a_{k-1} + 1 \).
   - Therefore, the total number of balanced sequences of length \( n \) is \( 2^{n-1} \).

### Part (b)
1. **Condition for \( a_n = m \)**:
   We need to count the number of balanced sequences of length \( n \) such that the last term \( a_n = m \).

2. **Recursive Construction**:
   - To have \( a_n = m \), there must be exactly \( m \) distinct numbers in the sequence.
   - The sequence must reach \( m \) distinct numbers by the \( n \)-th term.

3. **Combinatorial Counting**:
   - We need to choose \( m-1 \) positions out of the first \( n-1 \) positions to introduce new distinct numbers (since \( a_1 \) is always 1).
   - The number of ways to choose \( m-1 \) positions out of \( n-1 \) is given by the binomial coefficient \( \binom{n-1}{m-1} \).

The final answer is (a) \( \boxed{ 2^{n-1} } \) and (b) \( \binom{n-1}{m-1} \).