#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long extended_gcd(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long x1, y1;
  long long d = extended_gcd(b, a % b, x1, y1);
  x = y1;
  y = x1 - y1 * (a / b);
  return d;
}
vector<int> sieveoferatosthenes(int n) {
  vector<bool> prime(n + 1, true);
  for (int i = 2; i <= sqrt(n); i++) {
    if (prime[i]) {
      for (int j = i * i; j <= n; j += i) {
        prime[j] = false;
      }
    }
  }
  vector<int> all_primes;
  for (int i = 2; i <= n; i++) {
    if (prime[i]) all_primes.push_back(i);
  }
  return all_primes;
}
long long bin_exp(long long a, long long b, long long mod) {
  long long ans = 1;
  while (b) {
    if (b % 2) {
      b--;
      ans = (ans % mod * a % mod) % mod;
    }
    b /= 2;
    a = (a % mod * a % mod) % mod;
  }
  return ans;
}
void bfs(vector<int>& distance, vector<int> a[], vector<bool>& visited, int u,
         vector<int>& parent) {
  visited[u] = true;
  parent[u] = -1;
  distance[u] = 0;
  queue<int> q;
  q.push(u);
  while (!q.empty()) {
    int f = q.front();
    q.pop();
    for (int i = 0; i < a[f].size(); i++) {
      if (visited[a[f][i]] == false) {
        distance[a[f][i]] = distance[f] + 1;
        parent[a[f][i]] = f;
        visited[a[f][i]] = true;
        q.push(a[f][i]);
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m, s, c, f = 0;
  cin >> n >> m;
  vector<int> a(n + 1, -1);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (a[s] == -1)
      a[s] = c;
    else if (a[s] != -1 and a[s] != c) {
      f = 1;
    }
  }
  if (f) {
    cout << -1 << endl;
  } else {
    if (n != 1) {
      if (a[1] == 0) {
        cout << -1 << endl;
      } else {
        for (int i = 0; i < n; i++) {
          if (a[i + 1] == -1) {
            cout << 0;
          } else {
            cout << a[i + 1];
          }
        }
        cout << endl;
      }
    } else {
      cout << a[1] << endl;
    }
  }
  return 0;
}
