#include <bits/stdc++.h>
using namespace std;
void print(bool c) {
  if (c)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void Print(bool c) {
  if (c)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
long long int gcdll(long long int a, long long int b) {
  while (1) {
    if (a < b) swap(a, b);
    if (b == 0) break;
    a %= b;
  }
  return a;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  if (a.second != b.second) return a.second < b.second;
  return a.first < b.first;
}
int kaijo(int x) {
  int ans = 1;
  for (int i = 1; i < x + 1; i++) ans *= i;
  return ans;
}
string n_shin(int x, int n) {
  string s;
  while (x > 0) {
    s += to_string(x % n + 1);
    x /= n;
  }
  while (s.size() < n) {
    s += '0';
  }
  s.reserve();
  return s;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < m; i++) cin >> s[i] >> c[i];
  int i = -1;
  while (1) {
    i++;
    string t = to_string(i);
    if (t.size() > n) {
      cout << -1 << endl;
      return 0;
    }
    if (t.size() != n) continue;
    for (int j = 0; j < m; j++) {
      if (t[s[j] - 1] - '0' != c[j]) break;
      if (j == m - 1) {
        cout << i << endl;
        return 0;
      }
    }
  }
}
