C program to print all numbers with different digits in interval

I need to make a program in C, which outputs all numbers with different digits in interval entered by the user. Here is what I’ve come up with.

#include<stdio.h>

int main(){
int n, m, k = 0, p, flag, last, temp;
do{
    printf("Enter m and n (m < n):\n"); scanf("%d %d", &m, &n);
    if (m < n) {
        break;
    }
    else printf("\Error- m > n! Try again.\n\n");
} while (k == 0);

printf("Numbers are:\n");
for (k = m; k <= n; k++) {
    p = k;
    flag = 0;
    if (p < 10) {
        flag = 1;
    }
    last = (p / 10) % 10 ;
    while (p > 0) {
        temp = p % 10; 
        p = p / 10; 
        if (temp == last ){ 
            flag = 1;                                              
        }
        last = temp; 
    }
    if (flag != 1) { 
        printf("%d ", k);
    }
}
getch();
return 0;
}

Example output:

Enter m and n (m < n):
100 130
Numbers are:
101 102 103 104 105 106 107 108 109 120 121 123 124 125 126 127 128 129 130

So the problem in this case is that it outputs 101 and 121. It shouldn’t because they have two same digits. How do I fix that?

C program to print all numbers with different digits in interval