Let $K$ and $N > K$ be fixed positive integers. Let $n$ be a positive integer and let $a_1, a_2, ..., a_n$ be distinct integers. Suppose that whenever $m_1, m_2, ..., m_n$ are integers, not all equal to $0$, such that $\mid{m_i}\mid \le K$ for each $i$, then the sum
$$\sum_{i = 1}^{n} m_ia_i$$
is not divisible by $N$. What is the largest possible value of $n$?

[i]Proposed by Ilija Jovcevski, North Macedonia[/i]
1. **Define the Set \( A \)**:
   Consider the set:
   \[
   A = \left\{ m_1a_1 + m_2a_2 + \cdots + m_na_n \mid 0 \le m_i \le K, (m_1, m_2, \dots, m_n) \neq (0, 0, \dots, 0) \right\}
   \]
   This set \( A \) contains all possible sums formed by the integers \( a_1, a_2, \ldots, a_n \) with coefficients \( m_i \) ranging from 0 to \( K \), excluding the case where all \( m_i \) are zero.

2. **Calculate the Size of \( A \)**:
   The number of elements in \( A \) is:
   \[
   |A| = (K+1)^n - 1
   \]
   This is because each \( m_i \) can take \( K+1 \) values (from 0 to \( K \), inclusive), and we exclude the all-zero tuple.

3. **Condition for Distinct Elements Modulo \( N \)**:
   If there exist two elements in \( A \) that are equivalent modulo \( N \), their difference would be divisible by \( N \). This difference can be written as:
   \[
   t_1a_1 + t_2a_2 + \cdots + t_na_n
   \]
   where \( |t_i| \le K \) for each \( i \). This would violate the given condition that such a sum is not divisible by \( N \).

4. **Ensuring All Elements are Distinct Modulo \( N \)**:
   Therefore, all elements in \( A \) must be distinct modulo \( N \) and none of them can be divisible by \( N \). Hence, we have:
   \[
   (K+1)^n - 1 \le N - 1
   \]
   Simplifying this inequality, we get:
   \[
   (K+1)^n \le N
   \]

5. **Finding the Largest Possible \( n \)**:
   To find the largest possible \( n \), we take the logarithm base \( K+1 \) of both sides:
   \[
   n \le \lfloor \log_{K+1}(N) \rfloor
   \]

6. **Constructing a Valid Set of \( a_i \)**:
   Let \( n_0 = \lfloor \log_{K+1}(N) \rfloor \). We need to show that \( n = n_0 \) is achievable. Consider the set:
   \[
   \{a_1, a_2, \ldots, a_{n_0}\} = \{1, K+1, (K+1)^2, \ldots, (K+1)^{n_0-1}\}
   \]
   If there exist integers \( m_1, m_2, \ldots, m_{n_0} \), not all zero, such that \( |m_i| \le K \) and:
   \[
   \sum_{i=1}^{n_0} m_i a_i \equiv 0 \pmod{N}
   \]
   then by separating the terms \( m_i a_i \) according to the sign of \( m_i \), there would exist two distinct elements of \( A \) which are equivalent modulo \( N \), or an element of \( A \) which is divisible by \( N \). This is impossible since each element of \( A \) is positive and less than \( N \) because:
   \[
   0 < \sum_{i=1}^{n_0} m_i a_i \le \sum_{i=1}^{n_0} K (K+1)^{i-1} = (K+1)^{n_0} - 1 < N
   \]
   and they are all distinct due to being different numbers written in base \( K+1 \).

The final answer is \( \boxed{\lfloor \log_{K+1}(N) \rfloor} \)