Also, maybe recommendation from Codex will be helpful for you:
<?php$the_slug='my-slug';$args=array('name'=>$the_slug,'post_type'=>'post','post_status'=>'publish','posts_per_page'=>1);$my_posts= get_posts($args);if($my_posts){echo'ID on the first post found '.$my_posts[0]->ID;}?>
Also, maybe recommendation from Codex will be helpful for you:
BTW, why you need to get post ID by slug?
Write a comment