#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1001001001;
const vector<int> di = {-1, 0, 1, 0};
const vector<int> dj = {0, -1, 0, 1};
void chmin(int &a, int b) {
  if (a > b) a = b;
}
ll GCD(ll a, ll b) {
  if (b == 0)
    return a;
  else
    return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> num;
  for (int(i) = 0; (i) < (N); (i)++) num[i] = 10;
  for (int(i) = 0; (i) < (M); (i)++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (N > 1) {
      if (s == 0 && c == 0) {
        cout << -1 << endl;
        return 0;
      }
    }
    if (num[s] != 10 && num[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    num[s] = c;
  }
  if (M == 0) {
    if (N == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  }
  for (int(i) = 0; (i) < (N); (i)++) {
    if (num[i] == 10)
      cout << 0;
    else
      cout << num[i];
  }
  cout << endl;
}
