use std::io::BufReader;
use std::io;
use std::io::prelude::*;

fn main() {

    let mut first = true;
    let mut N :i32 = 0;
    let mut M: i32 = 0;
    let mut svec = Vec::new();
    let mut cvec = Vec::new();
    let stdin = io::stdin();
    for line in stdin.lock().lines() {
        let s: Vec<String> = line.unwrap().split(' ').map(|s| String::from(s)).collect();
        if first {
            N = s[0].parse::<i32>().unwrap();
            M = s[1].parse::<i32>().unwrap();
        } else {
            let sv = s[0].parse::<i32>().unwrap();
            let cv = s[1].parse::<i32>().unwrap();
            svec.push(sv);
            cvec.push(cv);
        }
        first = false
    }

    let mut val = Vec::new();
    for i in 0..N {
        val.push(-1);
    }

    for i in 0..svec.len() {
        let pos = (svec[i as usize] - 1) as usize;
        if val[pos] != -1 && val[pos] != cvec[i as usize] {
            println!("-1");
            return
        }
        val[pos] = cvec[i as usize] ;
    }

    if val[0] == -1 {
        if N > 1 {
            val[0] = 1
        }
    } else {
        if N > 1 && val[0] == 0 {
            println!("-1");
            return
        }
    }

    for i in 1..N {
        if val[i as usize] == -1 {
            val[i as usize] = 0
        }
    }

    let ans: String = val.iter().map(|v| v.to_string()).collect();

    println!("{}", ans);
}