#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const int inf = 1e9 + 7;
const long long int linf = 1LL << 60;
using str = string;
const double PI = 3.14159265359;
long long int gcd(long long int a, long long int b) {
  long long int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}
int gcd(int a, int b) {
  int t;
  while (b != 0) {
    t = a % b;
    a = b;
    b = t;
  }
  return a;
}
long long int recfact(long long int start, long long int n) {
  long long int i;
  if (n <= 16) {
    long long int r = start;
    for (i = start + 1; i < start + n; i++) r = r * i % mod;
    return r % mod;
  }
  i = n / 2;
  return recfact(start, i) % mod * recfact(start + i, n - i) % mod;
}
long long int lcm(long long int a, long long int b) {
  return a * b / gcd(a, b);
}
long long int fct(long long int n) { return recfact(1, n); }
long long int ncm(long long int n, long long int m) {
  if (n < m) return 0;
  long long int x = (fct(n) % mod / (fct(m) * fct(n - m)) % mod) % mod;
  return x;
}
std::string sreverse(string str, int firstItr, int secondItr) {
  if (firstItr < 0 || secondItr > int(str.size() - 1)) return str;
  while (firstItr < secondItr) {
    swap(str[firstItr], str[secondItr]);
    firstItr++;
    secondItr--;
  }
  return str;
}
std::string RunLengthEncoding(std::string str) {
  int itr = 0;
  std::string res;
  while (itr < int(str.size())) {
    char tmp = str[itr++];
    int length = 1;
    while (itr < int(str.size()) && str[itr] == tmp) {
      ++itr;
      ++length;
    }
    res.push_back(tmp);
    res += to_string(length);
  }
  return res;
}
std::string split(std::string str, size_t first_itr, bool isFront) {
  if (first_itr < 0 || first_itr > str.size()) {
    return str;
  } else {
    if (isFront) {
      std::string tmp;
      for (size_t i = 0; i < first_itr; i++) {
        tmp.push_back(str.at(i));
      }
      return tmp;
    } else {
      std::string tmp;
      for (size_t i = first_itr; i < str.size(); i++) {
        tmp.push_back(str.at(i));
      }
      return tmp;
    }
  }
}
bool dfs(int depth, str s) { return false; }
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> v(n);
  vector<bool> b(n);
  for (int i = 0; i < (int)n; i++) {
    v[i] = 0;
    b[i] = true;
  }
  for (int i = 0; i < (int)m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (b[s]) {
      v[s] = c;
    } else if (v[s] == c) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (v[0] != 0) {
    for (int i = 0; i < (int)n; i++) {
      cout << v[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
