#include <bits/stdc++.h>
using namespace std;
using in = int64_t;
const double PI = 3.14159265358979323846;
const in MOD = 1000000007;
const in INF = 1 << 30;
using P = pair<int, int>;
vector<int> dx = {0, 1, -1, 0};
vector<int> dy = {1, 0, 0, -1};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  vector<int> s(m), c(m);
  for (int i = 0; i < (int)(m); i++) cin >> s[i] >> c[i];
  vector<int> a(n, 0);
  bool flag = 1;
  for (int i = 0; i < (int)(m); i++) s[i]--;
  for (int i = 0; i < (int)(m); i++) {
    if (a[s[i]] != 0 && a[s[i]] != c[i]) {
      flag = 0;
      break;
    }
    a[s[i]] = c[i];
    if (s[i] == 0 && c[i] == 0) {
      flag = 0;
      break;
    }
  }
  if (!flag) {
    cout << -1 << endl;
    return 0;
  } else if (a[0] == 0) {
    a[0] = 1;
  }
  for (int i = 0; i < (int)(n); i++) cout << a[i];
  cout << endl;
}
