#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (m); ++i) cin >> s[i] >> c[i];
  if (m == 0) {
    if (n == 1)
      cout << 0 << endl;
    else {
      cout << pow(10, n - 1) << endl;
    }
    return 0;
  }
  if (n == 1) {
    int res = c[0];
    for (int i = 0; i < (m); ++i) {
      if (c[i] != res) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << res << endl;
  }
  if (n == 2) {
    vector<int> res(3, 0);
    for (int i = 0; i < (m); ++i) {
      res[s[i]] = c[i];
    }
    for (int i = 0; i < (m); ++i) {
      if (c[i] != res[s[i]]) {
        cout << -1 << endl;
        return 0;
      }
      if (res[1] == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << res[1] << res[2] << endl;
  }
  if (n == 3) {
    vector<int> res(4, 0);
    for (int i = 0; i < (m); ++i) {
      res[s[i]] = c[i];
    }
    for (int i = 0; i < (m); ++i) {
      if (c[i] != res[s[i]]) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (res[1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    cout << res[1] << res[2] << res[3] << endl;
  }
  return 0;
}
