#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
bool chmax(T &a, const U &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T, class U>
bool chmin(T &a, const U &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
const int INF = 1e9, MOD = 1e9 + 7;
const long long LLINF = 1e16;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int n;
  cin >> n;
  int m;
  cin >> m;
  vector<int> vi(n, -1);
  auto ans = 0;
  for (int i = 0; i < int(m); i++) {
    int s;
    cin >> s;
    int c;
    cin >> c;
    if (vi[s - 1] == -1) {
      vi[s - 1] = c;
    } else {
      if (vi[s - 1] != c) ans = -1;
    }
  }
  if (ans != -1) {
    string str;
    for (int i = 0; i < int(n); i++) {
      if (vi[i] == -1) {
        str += "x";
      } else {
        str += to_string(vi[i]);
      }
    }
    bool numbered = false;
    for (int i = 0; i < int(n); i++) {
      if (vi[i] == '0' && !(numbered)) {
        if (n == 1) {
          vi[i] = '0';
        } else {
          str = "-1";
          break;
        }
      } else if (vi[i] == 'x' && !(numbered)) {
        if (n == 1) {
          vi[i] = '0';
        } else {
          vi[i] = '1';
        }
        numbered = true;
      } else if (vi[i] == 'x' && numbered) {
        vi[i] = '0';
      } else {
        numbered = true;
      }
    }
    ans = stoi(str);
  }
  cout << ans << endl;
  return 0;
}
