#include <bits/stdc++.h>
using namespace std;
using ipair = pair<int, int>;
long long INF = 1e16 + 7;
bool operator>(const ipair a, const ipair b) { return a.first > b.first; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<ipair> cond;
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    s--;
    cond.push_back(make_pair(s, c));
  }
  int start, end;
  if (N == 1) {
    start = 0;
    end = 10;
  } else if (N == 2) {
    start = 10;
    end = 100;
  } else if (N == 3) {
    start = 100;
    end = 1000;
  }
  int ans = -1;
  for (int num = start; num < end; num++) {
    string str = to_string(num);
    for (int i = 0; i < (M); ++i) {
      int s = cond[i].first;
      int c = cond[i].second;
      if (str[s] - '0' != c) {
        ans = -1;
        break;
      }
      ans = num;
    }
    if (ans != -1) {
      cout << ans << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}
