#include <bits/stdc++.h>
using namespace std;
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
int ddx[] = {-1, 0, 1, 0, -1, 1, -1, 1};
int ddy[] = {0, -1, 0, 1, 1, 1, -1, -1};
long long gcd(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return gcd(y, x % y);
}
long long lcm(long long x, long long y) { return (x * y) / gcd(x, y); }
int main() {
  int n, m, min = 1000;
  cin >> n >> m;
  int s[m], c[m];
  for (int i = 0; i < m; ++i) cin >> s[i] >> c[i];
  for (int i = 0; i < 1000; ++i) {
    string str = to_string(i);
    bool flag = true;
    for (int j = 0; j < m; ++j) {
      if (s[j] > str.length() || str[s[j] - 1] - '0' != c[j]) {
        flag = false;
        break;
      }
    }
    if (n > 1 && i == 0) flag = false;
    if (flag) {
      if (min > i) min = i;
    }
  }
  if (min == 1000)
    cout << -1 << endl;
  else
    cout << min << endl;
  return 0;
}
