#include <bits/stdc++.h>
using namespace std;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T *)array, (T *)(array + N), val);
}
void pyn(bool ans) { cout << (ans ? "Yes" : "No") << endl; }
bool is_prime(long long n) {
  if (n == 1) return false;
  for (long long i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
vector<long long> divisor(long long n) {
  vector<long long> res;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      res.push_back(i);
      if (i != n / i) res.push_back(n / i);
    }
  }
  return res;
}
map<long long, int> prime_factor(long long n) {
  map<long long, int> res;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      res[i]++;
      n /= i;
    }
  }
  if (n != 1) res[n]++;
  return res;
}
vector<long long> prime_enum(int n) {
  vector<bool> is_prime(n + 1, true);
  is_prime[0] = is_prime[1] = false;
  vector<long long> res;
  for (int i = 2; i <= n; i++) {
    if (!is_prime[i]) continue;
    res.push_back(i);
    for (int j = 2 * i; j <= n; j += i) {
      is_prime[j] = false;
    }
  }
  return res;
}
long long fact[100001];
long long mpow(long long x, long long y) {
  if (y == 0) return 1;
  if (y % 2 == 0) {
    return mpow(x * x % (long long)(1e9 + 7), y / 2) % (long long)(1e9 + 7);
  } else {
    return x * mpow(x, y - 1) % (long long)(1e9 + 7);
  }
}
long long minv(long long x) { return mpow(x, (long long)(1e9 + 7) - 2); }
void mfact() {
  fact[0] = 1;
  for (long long i = long long(1); i < long long(100001); ++i) {
    fact[i] = fact[i - 1] * i % (long long)(1e9 + 7);
  }
}
long long combi(long long n, long long k) {
  return (fact[n] * minv(fact[k]) % (long long)(1e9 + 7)) * minv(fact[n - k]) %
         (long long)(1e9 + 7);
}
long long llceil(long long a, long long b) {
  if (a >= 0) {
    return (a + b - 1) / b;
  } else {
    return a / b;
  }
}
long long llfloor(long long a, long long b) {
  if (a < 0) {
    return (a - b + 1) / b;
  } else {
    return a / b;
  }
}
struct UnionFind {
  vector<long long> data;
  UnionFind(int size) : data(size, -1) {}
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y];
      data[y] = x;
    }
    return x != y;
  }
  bool find(int x, int y) { return root(x) == root(y); }
  int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
  long long size(int x) { return -data[root(x)]; }
  long long num_root(long long size) {
    vector<long long> roots;
    for (long long i = long long(0); i < long long(size); ++i)
      roots.push_back(root(i));
    sort((roots).begin(), (roots).end());
    roots.erase(unique((roots).begin(), (roots).end()), roots.end());
    return roots.size();
  }
};
long long a[100001], b[100001], c[100001], d, n, m, x, y, z, h, w, k,
    mi = (long long)1e9, ma = -(long long)1e9, ans, s, t, l, r, res, tmp, itr,
    p, q;
bool flag;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int dx8[8] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
char cha;
string st;
pair<long long, long long> pa;
bool fl;
int main(void) {
  cin >> n >> m;
  for (long long i = long long(0); i < long long(m); ++i) {
    cin >> a[i] >> b[i];
  }
  for (long long i = long long(1); i < long long(1000); ++i) {
    st = to_string(i);
    if (i < 10)
      d = 1;
    else if (i < 100)
      d = 2;
    else
      d = 3;
    if (d == n) {
      fl = 1;
      for (long long j = long long(0); j < long long(m); ++j) {
        if (st[a[j] - 1] != b[j]) fl = 0;
      }
      if (fl) {
        cout << (i) << endl;
        return 0;
      }
    }
  }
  cout << (-1) << endl;
  return 0;
}
