#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  long long c;
  if (a < b) {
    c = a;
    a = b;
    b = c;
  }
  while (b != 0) {
    c = a % b;
    a = b;
    b = c;
  }
  return a;
}
long long lcm(long long a, long long b) {
  long long c;
  c = a * b / gcd(a, b);
  return c;
}
struct UnionFind {
  vector<int> r;
  UnionFind(int n) { r = vector<int>(n, -1); }
  int root(int x) {
    if (r[x] < 0) return x;
    return r[x] = root(r[x]);
  }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (r[x] > r[y]) swap(x, y);
    r[x] += r[y];
    r[y] = x;
    return true;
  }
  int size(int x) { return -r[root(x)]; }
};
int bubblesort(int a[], int n) {
  int sw = 0;
  bool flag = 1;
  for (int i = 0; flag; i++) {
    flag = 0;
    for (int j = n - 1; j >= i + 1; j--) {
      if (a[j] < a[j - 1]) {
        swap(a[j], a[j - 1]);
        flag = 1;
        sw += 1;
      }
    }
  }
  return sw;
}
int a_z() {
  for (int i = 0; i <= ('Z' - 'A'); i++) {
    cout << (char)('A' + i);
  }
  return 0;
}
int selecttionsort(int a[], int n) {
  int t, sw = 0, minj;
  for (int i = 0; i < n - 1; i++) {
    minj = i;
    for (int j = 0; j < n - 1; j++) {
      if (a[j] < a[minj]) {
        minj = j;
      }
    }
    t = a[i];
    a[i] = a[minj];
    a[minj] = t;
    if (i != minj) sw += 1;
  }
  return sw;
}
bool is_prime(int x) {
  if (x <= 1) return false;
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}
const long long mod = 1000000007;
map<string, int> memo;
using P = pair<long long, long long>;
long long findIndex(int value, vector<long long> a) {
  for (long long i = 0; i < (long long)a.size(); i++) {
    if (a[i] == value) {
      return i;
    }
  }
  return -1;
}
struct mint {
  long long x;
  mint(long long x = 0) : x(x % mod) {}
  mint pow(long long t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod - 2); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) {
    mint res(*this);
    return res *= a;
  }
  mint operator/(const mint a) {
    mint res(*this);
    return res /= a;
  }
};
struct combination {
  vector<mint> fact, ifact;
  combination(long long n) : fact(n + 1), ifact(n + 1) {
    fact[0] = 1;
    for (long long i = 1; i <= n; i++) fact[i] = fact[i - 1] * i;
    ifact[n] = fact[n].inv();
    for (long long i = n; i >= 1; i--) {
      ifact[i - 1] = ifact[i] * i;
    }
  }
  mint operator()(long long n, long long k) {
    if (k < 0 || k > n) return 0;
    return fact[n] * ifact[k] * ifact[n - k];
  }
};
template <typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n = 0) : n(n), d(n + 1) {}
  void add(int i, T x = 1) {
    for (i++; i <= n; i += i & -i) {
      d[i] += x;
    }
  }
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i & -i) {
      x += d[i];
    }
    return x;
  }
  T sum(int l, int r) { return sum(r - 1) - sum(l - 1); }
};
const int INF = 1001001001;
const int M = 1000001;
string f(long long n) {
  if (n == 0) return "";
  n--;
  return f(n / 26) + string(1, 'a' + n % 26);
}
string x(long long n) {
  string s = "";
  if (n == 0) return "";
  n--;
  s += 'a' + n % 26;
  return x(n / 26) + s;
}
long long yakusuu(long long x) {
  long long anss = 1;
  vector<long long> a(x + 1);
  long long num = x;
  for (long long i = 2; i <= x; i++) {
    while (num % i == 0) {
      a.at(i)++;
      num /= i;
    }
  }
  for (long long i = 2; i <= x; i++) {
    anss *= a[i] + 1;
  }
  return anss;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (long long i = 0; i < (long long)(m); i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = pow(10, n - 1); i < pow(10, n); i++) {
    string a = to_string(i);
    bool x = true;
    for (long long j = 0; j < (long long)(m); j++) {
      if (n > 1) {
        if (s[j] == 1 && c[j] == '0') {
          cout << -1;
          return 0;
        }
      }
      if (a[s[j] - 1] != c[j]) x = false;
    }
    if (x) {
      cout << i;
      return 0;
    }
  }
  cout << -1;
  return 0;
}
