#include <bits/stdc++.h>
using namespace std;
class Graph {
  int V;
  list<pair<long long, long long>>* adj;
  const int INF = (int)1e6;

 public:
  Graph(int V) {
    this->V = V;
    adj = new list<pair<long long, long long>>[V];
  }
  void addEdge(int u, int v, int w) { adj[u].push_back(make_pair(v, w)); }
  long long edgeNum() {
    long long sum = 0;
    for (int i = 0; i < V; i++) sum += adj[i].size();
    return sum;
  }
  bool route(long long from, long long to) {
    vector<long long> vec(V, -1);
    dfs(1, from, vec);
    return vec[to] >= 0;
  }
  void dfs(long long ed, long long num, vector<long long>& vec) {
    for (auto e : adj[num]) {
      if (vec[e.first] != -1) continue;
      vec[e.first] = num;
      dfs(ed + 1, e.first, vec);
    }
  }
  vector<int> bfs(int n) {
    queue<int> q;
    vector<int> vec(V, -1);
    q.push(n);
    vec[n] = 0;
    while (!q.empty()) {
      int pair<long long, long long> = q.front();
      q.pop();
      for (auto e : adj[pair<long long, long long>]) {
        if (vec[e.first] == -1) {
          q.push(e.first);
          vec[e.first] = e.second + vec[pair<long long, long long>];
        }
      }
    }
    return vec;
  }
  vector<int> shortestPath(int src) {
    priority_queue<pair<long long, long long>,
                   vector<pair<long long, long long>>,
                   greater<pair<long long, long long>>>
        pq;
    vector<int> dist(V, INF);
    pq.push(make_pair(0, src));
    dist[src] = 0;
    while (!pq.empty()) {
      int u = pq.top().second;
      pq.pop();
      list<pair<int, int>>::iterator i;
      for (auto i = adj[u].begin(); i != adj[u].end(); ++i) {
        int v = (*i).first;
        int weight = (*i).second;
        if (dist[v] > dist[u] + weight) {
          dist[v] = dist[u] + weight;
          pq.push(make_pair(dist[v], v));
        }
      }
    }
    for (int i = 0; i < V; i++)
      if (dist[i] == INF) dist[i] = -1;
    return dist;
  }
};
pair<long long, long long> operator-(const pair<long long, long long>& l,
                                     const pair<long long, long long>& r) {
  return {l.first - r.first, l.second - r.second};
}
bool cmpf(const pair<long long, long long> left,
          const pair<long long, long long> right) {
  return left.first < right.first;
}
bool cmps(const pair<long long, long long> left,
          const pair<long long, long long> right) {
  return left.second < right.second;
}
void dfs(long long ed, long long num, vector<map<long long, long long>>& vec) {
  long long n = 1;
  for (auto e : vec[num]) {
    if (n == ed) n++;
    if (e.second != -1) continue;
    vec[num][e.first] = n;
    vec[e.first][num] = n;
    dfs(n, e.first, vec);
    n++;
  }
}
long long gcd(long long a, long long b) {
  if (a < b) return gcd(b, a);
  long long temp;
  while ((temp = a % b)) {
    a = b;
    b = temp;
  }
  return b;
}
struct nCr {
  vector<long long> f, rf;
  long long count = 0;
  nCr(long long num) : f(num), rf(num) {
    count = num;
    f[0] = 1;
    for (int i = 1; i <= num; i++) f[i] = (f[i - 1] * i) % 1000000007;
    for (int i = 0; i < num + 1; i++) rf[i] = inv(f[i]);
  }
  long long inv(long long x) {
    long long res = 1;
    long long k = 1000000007 - 2;
    long long y = x;
    while (k) {
      if (k & 1) res = (res * y) % 1000000007;
      y = (y * y) % 1000000007;
      k /= 2;
    }
    return res;
  }
  long long C(long long n, long long k) {
    long long a = f[n];
    long long b = rf[n - k];
    long long c = rf[k];
    long long bc = (b * c) % 1000000007;
    return (a * bc) % 1000000007;
  }
};
struct UF {
  vector<int> par, size;
  UF(int N) : par(N), size(N, 1) {
    for (int i = 0; i < N; i++) par[i] = i;
  }
  int root(int x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    if (rx == ry) return;
    par[rx] = ry;
    size[rx] += size[ry];
  }
  bool same(int x, int y) {
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
  int getSize(int x) { return size[x]; }
};
int main() {
  int n, m;
  cin >> n >> m;
  long long num[3];
  for (int i = 0; i < 3; i++) num[i] = -1;
  string str = "";
  for (int i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    if (num[s - 1] != c && num[s - 1] != -1) {
      cout << -1;
      return 0;
    }
    num[s - 1] = c;
  }
  if (num[0] == 0) {
    cout << -1;
    return 0;
  }
  str += to_string(num[0] == -1 ? 1 : num[0]);
  for (int i = 1; i <= n - 1; i++) str += to_string(num[i] == -1 ? 0 : num[i]);
  if (m == 0) str = "0";
  cout << str;
}
