I'm trying to implement this excercise but it doesn't work very well. It should tell me if the sequence in array B is contained in A. Any ideas? I have a problem getting it to work for every sequence.

```
#include <stdio.h>
#include <stdlib.h>

#define N 6
#define M 3

int contains(int v[], int n);

/*
 * 
 */
int main(int argc, char** argv)
{
    int A[N], B[M];
    int i, j = 0, flag = 0, contained = 1;

    printf("Array A\n");
    for (i = 0; i < N; i++)
    {
        printf("Insert element: ");
        scanf("%d", &A[i]);
    }

    printf("Array B\n");
    for (i = 0; i < M; i++)
    {
        printf("Insert element: ");
        scanf("%d", &B[i]);
    }

    for (i = 0; i < (N - M + 1); i++)
    {
        flag = 0;

        if (A[i] == B[j])
        {
            flag = 1;
            j++;
        }

        if (flag == 0 && (i == N-M))
        {
            contained = 0;
            printf("The sequence B is not contained in A!\n");
            break;
        }
    }

    if (contained == 1)
    {
        printf("The sequence B is contained in A\n");
    }

    return (EXIT_SUCCESS);
}

```