#include <bits/stdc++.h>
using namespace std;
const long long N = 7005;
const long long MOD = 1e9 + 7;
long long grid[3][3];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  long long second[m + 1], c[m + 1];
  for (int i = 1; i <= m; i++) cin >> second[i] >> c[i];
  long long lol = 9LL * pow(10LL, n - 1LL);
  for (long long x = 0; x <= lol; x++) {
    vector<long long> dig;
    long long y = x;
    while (y) {
      dig.push_back(y % 10);
      y /= 10;
    }
    if (dig.size() != n) continue;
    bool poss = true;
    reverse(dig.begin(), dig.end());
    for (int j = 1; j <= m; j++) {
      if (dig[second[j] - 1] != c[j]) {
        poss = false;
        break;
      }
    }
    if (poss) {
      cout << x << "\n";
      return 0;
    }
  }
  cout << "-1\n";
  return 0;
}
