#include <bits/stdc++.h>
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dr[4] = {-1, 0, 1, 0};
const int dc[4] = {0, 1, 0, -1};
const int INF = 1e9;
int guki(int a) {
  if (a % 2 == 0)
    return 0;
  else
    return 1;
}
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}
int lcm(int a, int b) {
  int x = gcd(a, b);
  return (a * b / x);
}
using namespace std;
struct UnionFind {
  vector<int> d;
  UnionFind(int n = 0) : d(n, -1) {}
  int Find(int x) {
    if (d[x] < 0) return x;
    return d[x] = Find(d[x]);
  }
  bool unite(int x, int y) {
    x = Find(x);
    y = Find(y);
    if (x == y) return false;
    if (d[x] < d[y]) {
      swap(x, y);
    }
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return Find(x) == Find(y); }
  int size(int x) { return (-d[Find(x)]); }
};
long long nCr(long long n, long long r) {
  long long ans = 1;
  for (long long i = n; i > n - r; i--) {
    ans *= i;
  }
  for (long long i = 1; i <= r; i++) {
    ans /= i;
  }
  return ans;
}
int nPr(int n, int r) {
  int ans = 1;
  for (int i = n; i > n - r; i--) {
    ans *= i;
  }
  return ans;
}
long long modd = 1e9 + 7;
long long wa(long long n, long long mi, long long ma) {
  long long ans = n * (mi + ma) / 2;
  return ans;
}
long long kw(long long k, long long n) {
  long long ans = 0;
  long long mi, ma;
  mi = wa(k, 0, k - 1);
  ma = wa(k, n - k + 1, n);
  return (ma - mi + 1) % modd;
}
int main() {
  int n, m;
  cin >> n >> m;
  string s = "";
  for (int i = (int)(0); i < (int)(n); ++i) {
    s += ".";
  }
  for (int i = (int)(0); i < (int)(m); ++i) {
    string k, c;
    cin >> k >> c;
    if (k != to_string(n) && c == "0") {
      cout << -1 << endl;
      return 0;
    }
    if (s[stoi(k) - 1] == '.') {
      s[stoi(k) - 1] = c[0];
    } else if (s[stoi(k) - 1] == c[0]) {
      continue;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = (int)(0); i < (int)(s.size()); ++i) {
    if (s[i] == '.') s[i] = '0';
  }
  cout << s << endl;
}
