#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long LLINF = 1LL << 60;
const int INF = 1 << 30;
class UnionFind {
 public:
  vector<int> rank;
  vector<int> p;
  UnionFind() {}
  UnionFind(int size) {
    rank.resize(size, 0);
    p.resize(size, 0);
    for (int i = 0; i < size; i++) {
      makeSet(i);
    }
  };
  void makeSet(int x) {
    p[x] = x;
    rank[x] = 0;
  }
  int findSet(int x) {
    if (x != p[x]) {
      p[x] = findSet(p[x]);
    }
    return p[x];
  }
  bool isSame(int x, int y) { return findSet(x) == findSet(y); }
  void unite(int x, int y) { link(findSet(x), findSet(y)); }

 private:
  void link(int x, int y) {
    if (rank[x] > rank[y]) {
      p[y] = x;
    } else {
      p[x] = y;
      if (rank[x] == rank[y]) {
        rank[y]++;
      }
    }
  }
};
const int MOD_NUM = 2;
class RollingHash {
  vector<long long> hash[MOD_NUM];
  vector<long long> mod = {999999937LL, 1000000007LL};
  long long base = 9973;

 public:
  RollingHash(string s) { initialize(s); }
  vector<long long> getHashNum(int left, int right) {
    vector<long long> res(MOD_NUM);
    for (int i = 0; i < MOD_NUM; i++) {
      res[i] = ((hash[i][right] -
                 hash[i][left] * this->mpower(base, right - left, mod[i])) %
                    mod[i] +
                mod[i]) %
               mod[i];
    }
    return res;
  }

 private:
  void initialize(string s) {
    for (int i = 0; i < MOD_NUM; i++) {
      hash[i].assign(s.size() + 1, 0);
      for (int j = 0; j < s.size(); j++) {
        hash[i][j + 1] = (hash[i][j] * base + s[j]) % mod[i];
      }
    }
  }
  long long mpower(long long x, long long n, long long mod) {
    if (n == 0) {
      return 1;
    } else if (n % 2 == 0) {
      return mpower(x * x % mod, n / 2, mod);
    } else {
      return x * mpower(x, n - 1, mod) % mod;
    }
  }
};
template <class T>
inline void chmax(T &a, T b) {
  if (a < b) {
    a = b;
  }
}
template <class T>
inline void chmin(T &a, T b) {
  if (a > b) {
    a = b;
  }
}
template <class T>
inline T lcm(T x, T y) {
  return x / __gcd(x, y) * y;
}
template <class T>
inline void coutvec(vector<T> vec) {
  for (int i = 0; i < vec.size(); i++) {
    cout << vec[i] << " ";
  }
  cout << endl;
}
template <class T>
inline T mpower(T x, T n) {
  if (n == 0) {
    return 1;
  } else if (n % 2 == 0) {
    return mpower(x * x % MOD, n / 2);
  } else {
    return x * mpower(x, n - 1) % MOD;
  }
}
int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  for (int i = 0; i < 999; i++) {
    string num = to_string(i);
    if (num.size() != N) {
      continue;
    }
    for (int j = 0; j < M; j++) {
      if (num[s[j]] != c[j]) {
        break;
      }
      if (j == M - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
