```
public int firstMissingPositive(int[] a) {
for(int i=0;i<a.length;i++){
if(!((a[i]<=0 || (a[i]>a.length))))
{
if(a[i]!=a[a[i]-1]){
int temp=a[a[i]-1];
a[a[i]-1]=a[i];
a[i]=temp;
i--;
}
}
}
int i=0;
while(i<a.length && a[i]==i+1){
i++;
}
return i+1;
}
```