//#define LOCAL
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mem(a, b) memset(a,b,sizeof(a))
#define INF 0x3f3f3f3f
#define DNF 0x7f
#define DBG printf("this is a input\n")
#define fi first
#define se second
#define mk(a, b) make_pair(a,b)
#define pb push_back
#define p_queue priority_queue
#define eps 1e-8
ll gcd(ll a, ll b) {
return b == 0 ? a : gcd(b, a % b);
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
int n , m , k;
struct node{
int t, next, c;
}edge[400005];
int head[20005], cnt = 0;
int mm[400005];
void add(int f, int t, int c)
{
edge[cnt].c = c;
edge[cnt].t = t;
edge[cnt].next = head[f];
head[f] = cnt ++;
}
int st, ed, level[20005], cur[20005];
bool DinicBfs(int s, int e)
{
mem(level,0);
queue<int>q;
q.push(s);
level[s] = 1;
while(!q.empty())
{
int root = q.front();
q.pop();
for(int i = head[root] ; i != -1 ; i = edge[i].next)
{
int v = edge[i].t, c = edge[i].c;
if(!level[v] && c > 0)
{
level[v] = level[root] + 1;
q.push(v);
}
}
}
return level[e] != 0;
}
int DinicDfs(int root , int flow)
{
if(root == ed)
return flow;
int newflow , cost = 0;
for(int& i = cur[root] ; i != -1 ; i = edge[i].next)
{
int v = edge[i].t, c = edge[i].c;
if(level[v] == level[root] + 1 && c > 0 && (newflow = DinicDfs(v,min(c,flow-cost))))
{
cost += newflow;
edge[i].c -= newflow;
edge[i^1].c += newflow;
if(cost == flow) break;
}
}
return cost;
}
int Dinic()
{
int ans = 0;
while(DinicBfs(st,ed))
{
for(int i = 0 ; i <= n+m+5 ; i ++)
cur[i] = head[i];
while(int add = DinicDfs(st,INF))
ans += add;
}
return ans;
}
int times , tot;
int dfn[20005] , low[20005], vis[20005], sta[20005], scc[20005], type = 0;
void tarjan(int u)
{
dfn[u] = low[u] = ++ times;
sta[++ tot] = u;
vis[u] = 1;
for(int i = head[u] ; i != -1 ; i = edge[i].next)
{
if(!edge[i].c) continue;
if(!dfn[edge[i].t])
{
tarjan(edge[i].t);
low[u] = min(low[u],low[edge[i].t]);
}
else if(vis[edge[i].t])
low[u] = min(low[u],dfn[edge[i].t]);
}
if(low[u] == dfn[u])
{
type ++;
do{
scc[sta[tot]] = type;
vis[sta[tot]] = 0;
tot --;
}while(u != sta[tot+1]);
}
return ;
}
int main(void)
{
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("odata.out", "w", stdout);
#endif
mem(head,-1);
cin>>n>>m>>k;
st = 0 , ed = n + m + 1;
for(int i = 1 ; i <= k ; i ++)
{
int x , y;
cin>>x>>y;
add(x,y+n,1),add(y+n,x,0);
}
for(int i = 1 ; i <= n ; i ++)
add(st, i,1), add(i, st, 0);
for(int i = 1 ; i <= m ; i ++)
add(i + n, ed,1), add(ed, i + n,0);
Dinic();
for(int i = 0; i <= ed ; i ++)
if(!dfn[i])
tarjan(i);
int ans = 0;
for(int i = 0 ; i < 2 * k ; i += 2)
{
//边(x,y)是可行边,要求(x,y)已是匹配边或(x,y)是非匹配边,但x和y处在同一个连通分量中。
//边(x,y)是必须边,要求(x,y)已是匹配边且x和y处在同一个连通分量中。
//!edge[i].c代表匹配边,后面代表同一连通分量
if(!edge[i].c || scc[edge[i].t] == scc[edge[i^1].t]) {
mm[i] = 1;
ans++;
}
}
cout<<k-ans<<endl;
if(ans == 0) {
cout<<endl;
return 0;
}
else
{
for(int i = 0 ; i < 2 * k ; i += 2)
{
if(!mm[i])
cout<<i/2+1<<" ";
}
}
cout<<endl;
}