#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int ans = pow(10, n - 1);
  if (ans == 1) ans = 0;
  vector<int> check(n);
  for (int i = 0; i < (n); ++i) check[i] = -1;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      if (n == 1)
        check[s - 1] = 0;
      else {
        ans = -1;
        break;
      }
    }
    if (check[s - 1] != -1) {
      if (check[s - 1] == c)
        continue;
      else {
        ans = -1;
        break;
      }
    }
    ans += pow(10, (n - s)) * c;
    check[s - 1] = c;
  }
  cout << ans;
}
